constint N = 10010,M = N * 2; int ne[M],e[M],h[N],w[M],idx; voidadd(int a,int b,int c){ w[idx] = c; e[idx] = b; ne[idx] = h[a]; h[a] = idx++; } intmain(){ memset(h,-1,sizeof(h)); int n,m; cin >> n >> m; while(m--) { int a,b,c; cin >> a >> b >> c; add(a,b,c),add(b,a,c); } return0; }
集合形式
constint N = 10010; structedge{ int to,w; }; vector<edge> v[N]; intmain(){ int n,m; cin >> n >> m; while(m--) { int a,b,c; cin >> a >> b >> c; v[a].push_back((edge){b,c}); v[b].push_back((edge){a,c}); } return0; }