結果
| 問題 |
No.807 umg tours
|
| コンテスト | |
| ユーザー |
eSeF
|
| 提出日時 | 2020-11-06 11:57:25 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 407 ms / 4,000 ms |
| コード長 | 2,289 bytes |
| コンパイル時間 | 1,758 ms |
| コンパイル使用メモリ | 128,836 KB |
| 最終ジャッジ日時 | 2025-01-15 20:02:39 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
#include<iostream>
#include<iomanip>
#include<limits>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<unordered_map>
#include<complex>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const ll infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;
#define rep(i,n) for (int i=0; i < (n); i++)
typedef double D; // 座標値の型。doubleかlong doubleを想定
typedef complex<D> P; // Point
typedef pair<P, P> L; // Line
typedef vector<P> VP;
typedef pair<int,int> PII;
typedef pair<ll,PII> Plii;
const D EPS = 1e-9; // 許容誤差。問題によって変える
#define X real()
#define Y imag()
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)
#define mkp(x,y) make_pair(x,y)
D dot(P a, P b) {
return (conj(a)*b).X;
}
struct E{
int t;
ll w;
E(int to,ll weight){
t=to;
w=weight;
}
};
vector<vector<E>>G;
ll dp[100010][2];
int main(){
cout << fixed << setprecision(10);
int N,M;
cin >> N >> M;
rep(i,N)G.push_back(vector<E>());
rep(i,M){
int a,b;ll c;
cin >> a >> b >> c;
a--;b--;
G[a].push_back(E(b,c));
G[b].push_back(E(a,c));
}
rep(i,100010)rep(j,2)dp[i][j]=infll;
dp[0][0]=dp[0][1]=0;
priority_queue<Plii>Q;
Q.push(mkp(0,mkp(0,0)));
while(!Q.empty()){
auto pl=Q.top();
Q.pop();
int v=pl.second.first;
int f=pl.second.second;
ll W=-pl.first;
if(dp[v][f]<W)continue;
for(auto e:G[v]){
//no ticket
if(dp[e.t][f]>W+e.w){
dp[e.t][f]=W+e.w;
Q.push(mkp(-(W+e.w),mkp(e.t,f)));
}
//use ticket
if(f==false){
if(dp[e.t][1]>W){
dp[e.t][1]=W;
Q.push(mkp(-W,mkp(e.t,1)));
}
}
}
}
for(int i=0;i<N;i++){
cout << dp[i][0]+dp[i][1] << "\n";
}
return 0;
}
eSeF