結果
| 問題 |
No.160 最短経路のうち辞書順最小
|
| コンテスト | |
| ユーザー |
kazuto0215
|
| 提出日時 | 2016-07-20 15:16:15 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,234 bytes |
| コンパイル時間 | 1,498 ms |
| コンパイル使用メモリ | 167,860 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-15 17:36:00 |
| 合計ジャッジ時間 | 2,636 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 25 RE * 1 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:26:27: warning: narrowing conversion of ‘b’ from ‘long long int’ to ‘int’ [-Wnarrowing]
26 | G[a].push_back((Edge){b, c});
| ^
main.cpp:26:30: warning: narrowing conversion of ‘c’ from ‘long long int’ to ‘int’ [-Wnarrowing]
26 | G[a].push_back((Edge){b, c});
| ^
main.cpp:27:27: warning: narrowing conversion of ‘a’ from ‘long long int’ to ‘int’ [-Wnarrowing]
27 | G[b].push_back((Edge){a, c});
| ^
main.cpp:27:30: warning: narrowing conversion of ‘c’ from ‘long long int’ to ‘int’ [-Wnarrowing]
27 | G[b].push_back((Edge){a, c});
| ^
ソースコード
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef struct {
int to, cost;
} Edge;
typedef pair <int, long long> P;
priority_queue <P> que;
long long n, m, a, b, st, go, c, node[222];
vector <Edge> G[222];
int main()
{
cin >> n >> m >> st >> go;
// グラフ入力
for (int i = 0; i < m; i++) {
cin >> a >> b >> c;
G[a].push_back((Edge){b, c});
G[b].push_back((Edge){a, c});
}
// node初期化
for (int i = 0; i < n; i++) {
node[i] = 1 << 20;
}
// ダイク
node[go] = 0;
que.push(P(go, 0));
while (!que.empty()) {
P p = que.top();
que.pop();
int v = p.F;
if (node[v] < p.S) {
continue;
}
for (int i = 0; i < G[v].size(); i++) {
Edge e = G[v][i];
if (node[e.to] > node[v] + e.cost) {
node[e.to] = node[v] + e.cost;
que.push(P(e.to, node[e.to]));
}
}
}
// 経路復元
int now = st, next;
while (now != go) {
next = 1 << 20;
cout << now << ' ';
for (int i = 0; i < G[now].size(); i++) {
Edge e = G[now][i];
if (node[e.to] + e.cost == node[now]) {
if (e.to < next) {
next = e.to;
}
}
}
now = next;
}
cout << go << endl;
}
kazuto0215