結果
| 問題 |
No.160 最短経路のうち辞書順最小
|
| コンテスト | |
| ユーザー |
hogeover30
|
| 提出日時 | 2015-03-26 05:19:26 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,128 bytes |
| コンパイル時間 | 799 ms |
| コンパイル使用メモリ | 64,740 KB |
| 最終ジャッジ日時 | 2024-11-14 19:01:15 |
| 合計ジャッジ時間 | 1,423 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp: In function ‘std::string dijkstra(int, int)’:
main.cpp:21:9: error: ‘tie’ was not declared in this scope
21 | tie(c, v)=q.top(); q.pop();
| ^~~
main.cpp:4:1: note: ‘std::tie’ is defined in header ‘<tuple>’; did you forget to ‘#include <tuple>’?
3 | #include <queue>
+++ |+#include <tuple>
4 | #include <string>
ソースコード
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
using namespace std;
vector<int> G[210];
int cost[210][210];
int n;
const int inf=1e9;
string dijkstra(int s, int g)
{
vector<int> d(n, inf);
vector<unsigned int> p(n, -1u);
priority_queue<pair<int, int>> q;
d[g]=0;
q.emplace(0, g);
while (q.size()) {
int c, v;
tie(c, v)=q.top(); q.pop();
if (d[v]<-c) continue;
for(int w: G[v]) {
if (d[w]>d[v]+cost[v][w] or d[w]==d[v]+cost[v][w] and p[w]>v) {
d[w]=d[v]+cost[v][w];
q.emplace(-d[w], w);
p[w]=v;
}
}
}
string res;
while (s!=g) {
res+=to_string(s)+' ';
s=p[s];
}
res+=to_string(g);
return res;
}
int main()
{
int m, s, g;
while (cin>>n>>m>>s>>g) {
for(int i=0;i<n;++i) G[i].clear();
for(int i=0;i<m;++i) {
int a, b, c; cin>>a>>b>>c;
G[a].push_back(b);
G[b].push_back(a);
cost[a][b]=cost[b][a]=c;
}
cout<<dijkstra(s, g)<<endl;
}
}
hogeover30