#include<bits/stdc++.h> usingnamespace std; vector<int> head, edge, Next, weight; int idx = 0; // 表示边的索引 voidadd_edge(int u, int v, int w){ edge[idx] = v; weight[idx]= w; Next[idx] = head[u]; head[u]=idx++;
} intmain(){ int n, m; cin >> n >> m; head.resize(n+1,-1); edge.resize(m+1); Next.resize(m+1); weight.resize(m+1); for (int i = 0; i<=m;i++){ int u,v,w; cin >> u >> v >> w; add_edge(u,v,w); } // 遍历 for (int i = 1;i<=n;i++){ for (int j = head[i]; ~j; j=Next[j]){ int u = i; int v = edge[j]; int w = weight[j]; printf("(%d, %d, %d)", u, v, w); } cout << endl; } return0; }
#include<bits/stdc++.h> #define endl '\n' usingnamespace std; typedeflonglong ll; typedef pair<int,int> PII; constint N = 2e5 + 10; constint mod = 1e9 + 7; int n, m, s, u, v, w, cnt; int head[100005]; structedge{ int to, dis, nxt; }edge[200005]; voidAdd_edge(int from, int to, int w){ edge[++cnt].to = to; edge[cnt].dis = w; edge[cnt].nxt = head[from]; head[from]=cnt; } voidsolve(){ cin >> n >> m; fill(head, head+n+1,-1); for (int i = 1;i<=n;i++){ cin >> u >> v >> w; Add_edge(u,v,w); } // 遍历 for (int i = 1;i<=n;i++){ for (int k = head[i];~k;k = edge[k].nxt){ /*具体处理*/ } } } intmain() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tomorin=1; cin >> tomorin; while (tomorin--) solve(); return0; }