#include <iostream>
#include <cstring>
using namespace std;
const int M=1005;
int head[M];
struct node
{
int to;
int w;
int next;
}Node[M];
int main()
{
int n,m;
cin>>n>>m;
memset(head,-1,sizeof(head));
for(int i=1;i<=m;i++)
{
int a,b,w;
cin>>a>>b>>w;
Node[i].to=b;
Node[i].w=w;
Node[i].next=head[a];
head[a]=i;
}
for(int i=1;i<=n;i++)
{
for(int k=head[i];k!=-1;k=Node[k].next)
cout<<i<<" "<<Node[k].to<<" "<<Node[k].w<<endl;
}
return 0;
}
/*
8 12
5 8 29
6 1 12
8 3 11
1 2 4
3 1 22
4 3 17
7 4 25
6 5 9
8 7 7
1 6 9
3 2 19
6 7 4
1 6 9
1 2 4
3 2 19
3 1 22
4 3 17
5 8 29
6 7 4
6 5 9
6 1 12
7 4 25
8 7 7
8 3 11
*/
链式前向星(图)
最新推荐文章于 2024-08-11 13:35:33 发布