adj[nd2].push_back(info(nd1,weight));
时间: 2024-05-29 10:12:23 浏览: 17
This line of code adds an edge from node nd1 to node nd2 with weight "weight" to the adjacency list of node nd2.
Explanation:
An adjacency list is a data structure that represents a graph as a list of vertices, where each vertex has a list of the vertices it is connected to. In this case, "adj" is an array of vectors, where each index in the array represents a node in the graph, and the vector at that index contains information about the edges connected to that node.
So, "adj[nd2]" accesses the vector of edges for node nd2, and ".push_back()" adds a new element to the end of the vector (in this case, a new "info" object representing the edge from nd1 to nd2 with weight "weight").
Overall, this line of code is adding a new edge to the graph representation stored in the "adj" array.
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)