結果
| 問題 |
No.160 最短経路のうち辞書順最小
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-02-29 06:58:13 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 24 ms / 5,000 ms |
| コード長 | 705 bytes |
| コンパイル時間 | 919 ms |
| コンパイル使用メモリ | 77,888 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-13 19:49:14 |
| 合計ジャッジ時間 | 2,581 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 26 |
コンパイルメッセージ
main.cpp:8:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
8 | main()
| ^~~~
ソースコード
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int N,M,S,g;
int d[200][200];
vector<pair<int,int> >G[200];
main()
{
cin>>N>>M>>S>>g;
for(int i=0;i<N;i++)for(int j=0;j<N;j++)d[i][j]=i==j?0:1e9;
for(int i=0;i<M;i++)
{
int a,b,c;cin>>a>>b>>c;
G[a].push_back(make_pair(b,c));
G[b].push_back(make_pair(a,c));
d[a][b]=d[b][a]=c;
}
for(int k=0;k<N;k++)for(int i=0;i<N;i++)for(int j=0;j<N;j++)
{
d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
}
cout<<S;
int now=S;
while(now!=g)
{
sort(G[now].begin(),G[now].end());
for(pair<int,int>p:G[now])
{
if(p.second+d[p.first][g]==d[now][g])
{
now=p.first;
break;
}
}
cout<<" "<<now;
}
cout<<endl;
}