結果

問題 No.807 umg tours
ユーザー lightninglightning
提出日時 2019-03-28 13:07:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,783 bytes
コンパイル時間 1,911 ms
コンパイル使用メモリ 178,828 KB
実行使用メモリ 17,052 KB
最終ジャッジ日時 2024-04-20 20:55:38
合計ジャッジ時間 8,582 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
5,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 2 ms
5,376 KB
testcase_05 WA -
testcase_06 AC 2 ms
5,376 KB
testcase_07 WA -
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 339 ms
14,920 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 262 ms
11,648 KB
testcase_21 AC 271 ms
11,776 KB
testcase_22 AC 114 ms
7,040 KB
testcase_23 AC 88 ms
6,144 KB
testcase_24 AC 281 ms
14,844 KB
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
#define all(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define TDARRAY(int,a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) {if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a, T b) {if(a>b){a=b;return 1;}return 0;}

struct edge{
    int to,cost;
};

int n,m;
vector<vector<edge>> g;
vector<vector<ll>> d(2);

int main(){
    cin >> n >> m;
    d[0].resize(n);
    d[1].resize(n);
    g.resize(n);
    
    vector<int> a(m);
    vector<int> b(m);
    vector<int> c(m);
    REP(i,m){
        cin >> a[i] >> b[i] >> c[i];
        a[i]--;b[i]--;
        
        edge e1;
        e1.to = b[i];
        e1.cost = c[i];
        g[a[i]].push_back(e1);
        
        edge e2;
        e2.to = a[i];
        e2.cost = c[i];
        g[b[i]].push_back(e2);
        
    }
    priority_queue<P,vector<P>,greater<P>> q;
    fill(all(d[0]),1e16);
    fill(all(d[1]),1e16);
    d[0][0]=d[1][0]=0;
    q.push(P(0,0));
    
    while(!q.empty()){
        P p = q.top();q.pop();
        int v = p.second;
        if(d[0][v]<p.first)continue;
        REP(i,g[v].size()){
            edge e = g[v][i];
            if(d[0][e.to]>d[0][v]+e.cost){
                d[0][e.to] = d[0][v]+e.cost;
                q.push(P(d[0][e.to],e.to));
            }
            chmin(d[1][e.to],min(d[1][v]+e.cost,d[0][v]));
            //put(e.cost);
        }
    }
    REP(i,n){
        put(d[0][i]+d[1][i]);
    }
    return 0;
}
0