#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int N = 1e5+10;
int head[N],idx;
struct Edge
{
int next;//当前点所指向的下一个点
int to; //边所指向的点
int val; //边的权值
}edge[N];
void add(int u,int v,int w)
{
edge[idx].val = w;
edge[idx].to = v;
edge[idx].next = head[u];
head[u] = idx++;
}
int main ()
{
int n,m;
scanf("%d%d",&n,&m);
while(m -- )
{
int u,v,w;
scanf("%d%d%d",&u,&v,&w);
add(u,v,w);
}
for (int i = 1; i <= n; i++ )
{
for (int j = head[i]; j != -1; j = edge[j].next)
{
printf("%d->%d的权值为%d\n",i,edge[j].to,edge[j].val);
}
}
return 0;
}
笔记-----链式前向星的板子
最新推荐文章于 2021-01-02 10:57:18 发布