結果
問題 | No.160 最短経路のうち辞書順最小 |
ユーザー | ふーらくたる |
提出日時 | 2016-07-01 15:50:22 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,380 bytes |
コンパイル時間 | 444 ms |
コンパイル使用メモリ | 55,684 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-10-12 00:01:20 |
合計ジャッジ時間 | 2,012 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,820 KB |
testcase_01 | AC | 1 ms
6,816 KB |
testcase_02 | AC | 1 ms
6,816 KB |
testcase_03 | AC | 2 ms
6,820 KB |
testcase_04 | AC | 15 ms
6,816 KB |
testcase_05 | AC | 18 ms
6,816 KB |
testcase_06 | AC | 20 ms
6,816 KB |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | AC | 11 ms
6,816 KB |
testcase_10 | AC | 13 ms
6,816 KB |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | AC | 12 ms
6,820 KB |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | AC | 11 ms
6,816 KB |
testcase_20 | AC | 11 ms
6,816 KB |
testcase_21 | AC | 12 ms
6,820 KB |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | AC | 10 ms
6,816 KB |
testcase_28 | AC | 22 ms
6,820 KB |
testcase_29 | AC | 9 ms
6,820 KB |
ソースコード
#include <iostream> using namespace std; const int kINF = 1 << 28; const int kMAX_N = 210; const int kMAX_M = kMAX_N * (kMAX_N - 1) / 2; int N, M, S, G; int cost[kMAX_N][kMAX_N]; int next_node[kMAX_N][kMAX_N]; int a[kMAX_M], b[kMAX_M], c[kMAX_M]; void WarshallFloyd() { for (int k = 0; k < N; k++) { for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (cost[i][j] > cost[i][k] + cost[k][j]) { cost[i][j] = cost[i][k] + cost[k][j]; next_node[i][j] = next_node[i][k]; } else if (cost[i][j] == cost[i][k] + cost[k][j] && next_node[i][j] > next_node[i][k]) { next_node[i][j] = k; } } } } } /* void RestoreRoute(int node, int start, int goal) { cout << node << " " << start << " " << goal << endl; if (node == start) { cout << node; return; } RestoreRoute(next_node[start][node], start, goal); cout << " " << node; if (node == goal) { cout << endl; } } */ /* #include <vector> vector<int> RestoreRoute(int node, int start, int goal) { if (node == start) { cout << node; return; } RestoreRoute(next_node[start][node], start, goal); cout << " " << node; if (node == goal) { cout << endl; } } */ void Solve() { for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (i == j) { cost[i][j] = 0; next_node[i][j] = kINF; } else { cost[i][j] = kINF; next_node[i][j] = j; } } } for (int i = 0; i < M; i++) { cost[a[i]][b[i]] = cost[b[i]][a[i]] = c[i]; } WarshallFloyd(); // RestoreRoute(G, S, G); /* int u, v; while (cin >> u >> v, u | v) { cout << "next " << next_node[u][v] << endl; } */ int node = S; cout << S; while (node != G) { node = next_node[node][G]; cout << " " << node; } cout << endl; /* cout << cost[S][G] << endl; int s, g; while (cin >> s >> g, s | g) { cout << next_node[s][g] << endl; } */ } int main() { cin >> N >> M >> S >> G; for (int i = 0; i < M; i++) { cin >> a[i] >> b[i] >> c[i]; } Solve(); return 0; }