typedef struct { int to; int w; int next; }Edge; Edge e[MAX]; int pre[MAX]; //初始化 memset(pre,-1,sizeof(pre)); //输入 scanf("%d %d %d",&from,&to,&w1); e[i].to = to; e[i].w = w1; e[i].next = pre[from]; pre[from] = i; i++;
- /*now为弧尾结点序号,i为now所发出的边序号,adj为弧头结点序号,w为now-->adj这条边的权值*/
- for(i = pre[now]; i != -1; i = edge[i].next)
- {
- int adj = edge[i].to;
- int w = edge[i].w;
- //do something...
- }