結果
| 問題 |
No.807 umg tours
|
| コンテスト | |
| ユーザー |
sinsincoscos
|
| 提出日時 | 2019-03-17 16:39:54 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 349 ms / 4,000 ms |
| コード長 | 1,082 bytes |
| コンパイル時間 | 702 ms |
| コンパイル使用メモリ | 77,828 KB |
| 実行使用メモリ | 42,256 KB |
| 最終ジャッジ日時 | 2024-11-23 18:47:30 |
| 合計ジャッジ時間 | 5,687 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
#include <iostream>
#include <vector>
#include <queue>
#include <stdio.h>
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
int N,M;
vector<vector<P>> v(200010);
ll dp[200010] = {},inf = 1e18;
int main(){
scanf("%d %d",&N,&M);
int a,b; ll c;
for(int i=0;i<M;i++){
scanf("%d %d %lld",&a,&b,&c);
v[a].push_back(P(c,b));
v[a].push_back(P(0,b+N));
v[b].push_back(P(c,a));
v[b].push_back(P(0,a+N));
v[a+N].push_back(P(c,b+N));
v[b+N].push_back(P(c,a+N));
}
for(int i=2;i<=2*N;i++){
if(i!=N+1) dp[i] = inf;
}
priority_queue<P,vector<P>,greater<P>> Q;
Q.push(P(0,1));
int cnt = 0;
while(!Q.empty()){
P p = Q.top(); Q.pop();
int n = p.second;
if(dp[n]<p.first) continue;
for(auto x:v[n]){
if(dp[x.second]>p.first+x.first){
dp[x.second] = p.first+x.first;
Q.push(P(dp[x.second],x.second));
}
}
}
for(int i=1;i<=N;i++){
printf("%lld\n",dp[i]+dp[i+N]);
}
}
sinsincoscos