struct node { int to; int next; int w; }E[50005]; int sum=0, head[50005], dist[50005],l1, l2; //分为k=1与k=2 void add(int m, int n) { sum++; //对应数目(权值),边的编号 E[sum].to = n; E[sum].next = head[m]; //以m为顶点时,head是每个顶点第一条边的编号 head[sum] = sum; E[sum].w = 1; }
时间: 2023-05-19 08:05:11 浏览: 25
这是一个关于图的数据结构的代码,其中包含了一个结构体 node,以及一个数组 E 和一些变量。函数 add 是用来添加边的,其中 m 和 n 分别表示边的起点和终点。在这个代码中,图被分为了两个部分,即 k=1 和 k=2。每条边都有一个权值,即 E[sum].w = 1。
相关问题
struct node { int to; int next; int w; }E[50005]; int sum=0, head[50005], dist[50005],l1, l2; //分为k=1与k=2 void add(int m, int n) { sum++; //对应边的数目,边的编号 E[sum].to = n;//边的终点 E[sum].next = head[m]; //表示下一条以m为起点的边的编号 head[sum] = sum;//head数组存储每个节点的第一条边的编号 E[sum].w = 1; }
这是一个关于图的数据结构的代码,使用邻接表来存储图。其中,节点的编号为to,边的编号为next,边的权值为w。add函数用于添加边,将起点为m,终点为n的边加入图中。head数组存储每个节点的第一条边的编号。
typedef struct node { int data; struct node *next; } NodeType;
This is a definition of a struct called "node" that has two members: an integer data member called "data" and a pointer to another node struct called "next". The struct is typedef'd as "NodeType" for convenience. This struct can be used to create linked lists, where each node contains a piece of data and a pointer to the next node in the list.
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.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)