結果
| 問題 |
No.160 最短経路のうち辞書順最小
|
| コンテスト | |
| ユーザー |
goodbaton
|
| 提出日時 | 2015-03-02 00:39:47 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,541 bytes |
| コンパイル時間 | 989 ms |
| コンパイル使用メモリ | 89,312 KB |
| 実行使用メモリ | 814,176 KB |
| 最終ジャッジ日時 | 2024-06-24 00:51:48 |
| 合計ジャッジ時間 | 4,772 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 3 MLE * 1 -- * 22 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:21:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
21 | scanf("%d%d%d%d",&n,&m,&s,&g);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:27:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
27 | scanf("%d%d%d",&a,&b,&c);
| ~~~~~^~~~~~~~~~~~~~~~~~~
ソースコード
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
using namespace std;
int main(){
int n,m,s,g,a,b,c,cost[200];
vector<pair<int,int> > way[200];
priority_queue<pair<int,pair<vector<int>,int> > > pq;
vector<int> vec;
scanf("%d%d%d%d",&n,&m,&s,&g);
for(int i=0;i<n;i++)
cost[i]=-1000000000;
for(int i=0;i<m;i++){
scanf("%d%d%d",&a,&b,&c);
way[a].push_back(make_pair(b,c));
way[b].push_back(make_pair(a,c));
}
vec.push_back(-s);
cost[s]=0;
for(int i=0;i<way[s].size();i++){
pq.push(make_pair(-way[s][i].second,make_pair(vec,way[s][i].first)));
}
while(1){
pair<int,pair<vector<int>,int> > p = pq.top();
pq.pop();
if(p.second.second==g){
for(int i=0;i<p.second.first.size();i++){
printf("%d ",-p.second.first[i]);
}
printf("%d\n",g);
break;
}
if(cost[p.second.second]>p.first) continue;
cost[p.second.second]=p.first;
vec = p.second.first;
vec.push_back(-p.second.second);
for(int i=0;i<way[p.second.second].size();i++){
pq.push(make_pair(p.first-way[p.second.second][i].second,make_pair(vec,way[p.second.second][i].first)));
}
}
return 0;
}
goodbaton