結果
| 問題 |
No.160 最短経路のうち辞書順最小
|
| コンテスト | |
| ユーザー |
ei1333333
|
| 提出日時 | 2016-07-21 16:07:50 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,055 bytes |
| コンパイル時間 | 1,566 ms |
| コンパイル使用メモリ | 170,252 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-11-06 02:35:18 |
| 合計ジャッジ時間 | 2,537 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 8 WA * 18 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:45:8: warning: use of an operand of type ‘bool’ in ‘operator++’ is deprecated [-Wdeprecated]
45 | if(first++) putchar(' ');
| ^~~~~
main.cpp:15:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
15 | scanf("%d %d %d %d", &N, &M, &S, &G);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:18:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
18 | scanf("%d %d %d", &a, &b, &c);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include<bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
typedef pair< int, int > Pi;
struct edge
{
int to, cost;
};
vector< edge > graph[10000];
int N, M, S, G;
int main()
{
scanf("%d %d %d %d", &N, &M, &S, &G);
while(M--) {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
graph[a].push_back((edge){b, c});
graph[b].push_back((edge){a, c});
}
priority_queue< Pi, vector< Pi >, greater< Pi > > que;
que.emplace(0, S);
vector< Pi > v(N, Pi(INF, INF));
v[S] = {0, -1};
while(!que.empty()) {
auto p = que.top(); que.pop();
for(auto& e : graph[p.second]) {
if(Pi(p.first + e.cost, p.second) >= v[e.to]) continue;
v[e.to] = Pi(p.first + e.cost, p.second);
que.emplace(v[e.to].first, e.to);
}
}
vector< int > dd;
int now = v[G].second;
dd.push_back(G);
while(now != -1) {
dd.push_back(now);
now = v[now].second;
}
bool first = false;
for(int i = dd.size() - 1; i >= 0; i--) {
if(first++) putchar(' ');
printf("%d", dd[i]);
}
putchar('\n');
}
ei1333333