結果
| 問題 |
No.807 umg tours
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-02-29 19:22:37 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 413 ms / 4,000 ms |
| コード長 | 2,054 bytes |
| コンパイル時間 | 1,929 ms |
| コンパイル使用メモリ | 180,592 KB |
| 実行使用メモリ | 42,180 KB |
| 最終ジャッジ日時 | 2024-11-23 19:51:49 |
| 合計ジャッジ時間 | 7,722 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define fore(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define rfore(i,a,b) for(ll i=(ll)(b);i>=(ll)(a);--i)
#define rrep(i,n) rfore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template< typename T >
struct edge {
int src, to;
T cost;
edge(int to, T cost) : src(-1), to(to), cost(cost) {}
edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
edge &operator=(const int &x) {
to = x;
return *this;
}
operator int() const { return to; }
};
template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;
void solve(){
ll n,m;cin>>n>>m;
WeightedGraph<ll> g(2*n);
while(m--){
ll a,b,c;cin>>a>>b>>c;
a--,b--;
g[a].emplace_back(b,c);
g[b].emplace_back(a,c);
g[a].emplace_back(b+n,0);
g[b].emplace_back(a+n,0);
g[a+n].emplace_back(b+n,c);
g[b+n].emplace_back(a+n,c);
}
vl d(2*n,LINF);
d[0]=d[n]=0;
priority_queue<pl,vp,greater<>> pq;
pq.push(pl(0,0));
while(!pq.empty()){
ll src,d1;
tie(d1,src)=pq.top();
pq.pop();
if(d1>d[src])continue;
for(auto &e:g[src]){
ll to=e.to,cost=e.cost;
if(d[to]<=d1+cost)continue;
d[to]=d1+cost;
pq.push(pl(d1+cost,to));
}
}
rep(i,n)cout<<(d[i]+d[i+n])<<endl;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(0);
solve();
}