- 图论
10个顶点50条边的有向图样例
- 2023-6-10 17:18:50 @
10 50
1 8 164
1 2 174
1 10 280
1 6 65
2 10 238
2 10 177
2 1 19
2 5 250
2 9 118
2 6 47
2 10 100
3 5 157
3 8 107
3 2 167
4 6 234
4 5 237
4 4 89
4 8 229
4 1 215
4 5 187
4 1 83
5 9 271
5 4 74
5 1 214
5 2 167
5 3 19
5 7 173
6 8 225
6 3 141
6 3 64
7 5 241
7 2 55
7 7 62
7 2 117
7 6 283
7 4 102
7 5 94
8 1 76
8 1 295
8 1 21
8 10 286
8 3 246
8 10 82
8 2 128
8 5 230
9 8 152
9 3 270
9 9 146
10 8 252
10 9 13
7 comments
-
任泽同 LV 10 @ 2023-6-17 10:34:50
👍 👍 👍 👍
-
2023-6-10 17:35:16@
👍 👍 👍
-
2023-6-10 17:34:44@
#include <bits/stdc++.h> using namespace std; #define TRACE 1 #define tcout TRACE && cout #define int long long #define endl '\n' #define fst ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); const int N = 20, M = 60; int n, m; int idx; int h[N]; int e[M]; int wt[M]; int ne[M]; void add_edge(int u, int v, int w) { idx++; e[idx] = v; wt[idx] = w; ne[idx] = h[u]; h[u] = idx; } signed main() { cin >> n >> m; for(int i=1; i<=m; i++) { int u, v, w; cin >> u >> v >> w; add_edge(u, v, w); } for(int i=1; i<=n; i++) { cout << i << ": "; for(int j=h[i]; j; j=ne[j]) { cout << "(" << e[j] << ", " << wt[j] << ") "; } cout << endl; } return 0; }
-
2023-6-10 17:34:34@
#include <bits/stdc++.h> using namespace std; #define TRACE 1 #define tcout TRACE && cout #define int long long #define endl '\n' #define fst ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); const int N = 20; struct Node { int v, w; bool operator< (const Node& b) { return v < b.v; } }; int n, m; vector<Node> g[N]; signed main() { cin >> n >> m; for(int i=1; i<=m; i++) { int u, v, w; cin >> u >> v >> w; g[u].push_back({v, w}); } for(int i=1; i<=n; i++) { sort(g[i].begin(), g[i].end()); cout << i << ":"; for(auto e: g[i]) { cout << "(" << e.v << ", " << e.w << ") "; } cout << endl; } return 0; }
-
2023-6-10 17:34:22@
#include <bits/stdc++.h> using namespace std; #define TRACE 1 #define tcout TRACE && cout #define int long long #define endl '\n' #define fst ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); const int INF = 0x3f3f3f3f3f3f3f3f; int n, m; int g[20][20]; signed main() { cin >> n >> m; for(int i=1; i<=n; i++) { for(int j=1; j<=n; j++) { if(i == j) { g[i][j] = 0; } else { g[i][j] = INF; } } } for(int i=1; i<=m; i++) { int u, v, w; cin >> u >> v >> w; g[u][v] = w; } for(int i=1; i<=n; i++) { for(int j=1; j<=n; j++) { if(g[i][j] == INF) { cout << " N"; } else { cout << setw(4) << g[i][j]; } } cout << endl; } return 0; }
-
2023-6-10 17:33:15@
👍 +1
-
2023-6-10 17:19:04@
👍
- 1