constint maxn = 10010; int n, m, G[maxn][maxn], dist[maxn], pre[maxn], s;
voidmake() { scanf("%d %d", &n, &m); for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) G[i][j] = INT_MAX; for (int i = 1; i <= n; ++i) G[i][i] = 0; for (int i = 1; i <= m; ++i) { int from, to, w; scanf("%d %d %d", &from, &to, &w); G[from][to] = w; } return; }
voidDijkstra() { int k, min; bool p[maxn]; for (int i = 1; i <= n; ++i) { p[i] = false; if (i != s) { dist[i] = G[s][i]; pre[i] = s; } } dist[s] = 0; p[s] = true; for (int i = 1; i <= n - 1; ++i) { min = INT_MAX; k = 0; for (int j = 1; j <= n; ++j) { if (!p[j] && dist[j] < min) { min = dist[j]; k = j; } } if (k == 0) return; p[k] = true; for (int j = 1; j <= n; ++j) { if (!p[j] && G[k][j] != INT_MAX && dist[j] > dist[k] + G[k][j]) { dist[j] = dist[k] + G[k][j]; pre[j] = k; } } } return; }