結果
| 問題 |
No.160 最短経路のうち辞書順最小
|
| コンテスト | |
| ユーザー |
zeosutt
|
| 提出日時 | 2015-05-08 00:01:10 |
| 言語 | C90 (gcc 12.3.0) |
| 結果 |
AC
|
| 実行時間 | 12 ms / 5,000 ms |
| コード長 | 904 bytes |
| コンパイル時間 | 109 ms |
| コンパイル使用メモリ | 21,760 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-05 20:07:55 |
| 合計ジャッジ時間 | 1,099 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 26 |
コンパイルメッセージ
main.c: In function ‘main’:
main.c:33:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
33 | scanf("%d %d %d %d", &n, &m, &s, &g);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.c:43:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
43 | scanf("%d %d %d", &a, &b, &c);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <stdio.h>
#define INF 1000000000
#define min(a, b) (((a) < (b)) ? (a) : (b))
int adj[200][200];
int next[200][200];
void warshall_floyd(int n) {
int i, j, k;
for (k = 0; k < n; k++)
for (i = 0; i < n; i++)
for (j = 0; j < n; j++)
if (adj[i][k] + adj[k][j] < adj[i][j]) {
adj[i][j] = adj[i][k] + adj[k][j];
next[i][j] = next[i][k];
} else if (adj[i][k] + adj[k][j] == adj[i][j])
next[i][j] = min(next[i][j], next[i][k]);
}
void printPath(int s, int g) {
for (; s != g; s = next[s][g])
printf("%d ", s);
printf("%d\n", g);
}
int main(void) {
int i, j;
int n, m, s, g;
scanf("%d %d %d %d", &n, &m, &s, &g);
for (i = 0; i < n; i++)
for (j = 0; j < n; j++) {
adj[i][j] = INF;
next[i][j] = j;
}
while (m--) {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
adj[a][b] = adj[b][a] = c;
}
warshall_floyd(n);
printPath(s, g);
return 0;
}
zeosutt