結果
| 問題 |
No.807 umg tours
|
| コンテスト | |
| ユーザー |
umezo
|
| 提出日時 | 2022-08-09 13:49:59 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 683 ms / 4,000 ms |
| コード長 | 1,646 bytes |
| コンパイル時間 | 2,096 ms |
| コンパイル使用メモリ | 205,744 KB |
| 最終ジャッジ日時 | 2025-01-30 19:41:22 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
const ll INF=1LL<<60;
struct Edge{
int to;
ll w;
Edge(int to,ll w) : to(to),w(w) {}
};
using Graph=vector<vector<Edge>>;
using pli=pair<ll,int>;
template<class T> bool chmin(T& a,T b){
if(a>b){
a=b;
return true;
}
return false;
}
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n,m;
cin>>n>>m;
Graph G(2*n),H(n);
rep(i,m){
int a,b;
ll w;
cin>>a>>b>>w;
a--,b--;
G[a].push_back(Edge(b,w));
G[b].push_back(Edge(a,w));
G[a].push_back(Edge(b+n,0));
G[b].push_back(Edge(a+n,0));
G[a+n].push_back(Edge(b+n,w));
G[b+n].push_back(Edge(a+n,w));
H[a].push_back(Edge(b,w));
H[b].push_back(Edge(a,w));
}
vector<ll> dist(2*n,INF),dist1(n,INF);
int s=0;
dist[s]=0;
dist1[s]=0;
priority_queue<pli,vector<pli>,greater<pli>> que,que1;
que.push({dist[s],s});
que1.push({dist1[s],s});
while(!que.empty()){
int v=que.top().second;
ll d=que.top().first;
que.pop();
if(d>dist[v]) continue;
for(auto e:G[v]){
if(chmin(dist[e.to],dist[v]+e.w)){
que.push({dist[e.to],e.to});
}
}
}
while(!que1.empty()){
int v=que1.top().second;
ll d=que1.top().first;
que1.pop();
if(d>dist1[v]) continue;
for(auto e:H[v]){
if(chmin(dist1[e.to],dist1[v]+e.w)){
que1.push({dist1[e.to],e.to});
}
}
}
cout<<0<<endl;
for(int i=1;i<n;i++) cout<<dist[i+n]+dist1[i]<<endl;
return 0;
}
umezo