#include <iostream>
#include <cstdio>
const int maxn = 1e7 + 5 ;
int u,v,d,used,n,m ;
struct edge_ {
int to ;
int next ;
int weight ;
}Edge[maxn * 2];
int head[maxn] ;
void push_edge (int from,int to,int d){
++used ;
Edge[used].to = to ;
Edge[used].weight = d ;
Edge[used].next = head[from] ;
head[from] = used ;
}
int main (){
scanf("%d%d",&n,&m) ;
for (int i = 1 ; i <= m ; ++i){
scanf("%d%d%d",&u,&v,&d) ;
push_edge(u,v,d) ;
push_edge(v,u,d) ;
}
for (int i = 1 ; i <= n ; ++i){
printf ("%d\n",i) ;
for (int j = head[i] ; j ; j = Edge[j].next)
printf ("%d %d\n",Edge[j].to,Edge[j].weight) ;
}
return 0 ;
}
C++数组模拟邻接表模板
最新推荐文章于 2023-02-06 12:06:26 发布