結果
| 問題 |
No.807 umg tours
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-04-20 02:18:04 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 441 ms / 4,000 ms |
| コード長 | 934 bytes |
| コンパイル時間 | 936 ms |
| コンパイル使用メモリ | 83,456 KB |
| 実行使用メモリ | 19,480 KB |
| 最終ジャッジ日時 | 2024-11-23 19:26:27 |
| 合計ジャッジ時間 | 7,016 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
コンパイルメッセージ
main.cpp:9:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
9 | main()
| ^~~~
ソースコード
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
int N,M;
vector<pair<int,int> >G[1<<17];
long d[2][1<<17];
main()
{
cin>>N>>M;
for(int i=0;i<M;i++)
{
int a,b,c;cin>>a>>b>>c;
G[a-1].push_back(make_pair(b-1,c));
G[b-1].push_back(make_pair(a-1,c));
}
for(int i=1;i<N;i++)d[0][i]=d[1][i]=9e18;
priority_queue<pair<long,pair<int,int> > >P;
P.push(make_pair(0,make_pair(0,0)));
while(!P.empty())
{
long c=-P.top().first;
int u=P.top().second.first;
int f=P.top().second.second;
P.pop();
if(d[f][u]<c)continue;
for(int i=0;i<G[u].size();i++)
{
int v=G[u][i].first;
if(d[f][v]>c+G[u][i].second)
{
d[f][v]=c+G[u][i].second;
P.push(make_pair(-d[f][v],make_pair(v,f)));
}
if(f==0)
{
if(d[1][v]>c)
{
d[1][v]=c;
P.push(make_pair(-c,make_pair(v,1)));
}
}
}
}
for(int i=0;i<N;i++)
{
cout<<d[0][i]+d[1][i]<<endl;
}
}