結果

問題 No.807 umg tours
ユーザー mtsdmtsd
提出日時 2019-03-22 21:39:59
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 540 ms / 4,000 ms
コード長 1,736 bytes
コンパイル時間 1,240 ms
コンパイル使用メモリ 95,464 KB
実行使用メモリ 23,688 KB
最終ジャッジ日時 2023-08-15 11:52:28
合計ジャッジ時間 8,275 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 3 ms
4,384 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 284 ms
15,008 KB
testcase_12 AC 297 ms
13,256 KB
testcase_13 AC 395 ms
16,228 KB
testcase_14 AC 167 ms
9,116 KB
testcase_15 AC 131 ms
7,840 KB
testcase_16 AC 410 ms
18,172 KB
testcase_17 AC 533 ms
22,584 KB
testcase_18 AC 527 ms
23,216 KB
testcase_19 AC 522 ms
20,200 KB
testcase_20 AC 315 ms
12,556 KB
testcase_21 AC 324 ms
12,920 KB
testcase_22 AC 136 ms
7,348 KB
testcase_23 AC 100 ms
6,212 KB
testcase_24 AC 301 ms
20,688 KB
testcase_25 AC 540 ms
23,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

vector<vector<pair<int,ll> > > g; 



int main(){
    int n,m;
    cin >> n >> m;
    g.resize(n);
    rep(i,m){
        int a,b;
        ll c;
        cin >> a >> b >> c;
        a--;b--;
        g[a].PB(MP(b,c));
        g[b].PB(MP(a,c));
    }
    vector<vector<ll> >dst(2,vector<ll>(n,1LL<<60));
    priority_queue<pair<ll,pair<int,int> >,vector<pair<ll,pair<int,int> > > ,greater<pair<ll,pair<int,int> > > > pq;
    dst[0][0] = 0;
    dst[1][0] = 0;
    pq.push(MP(0,MP(0,0)));
    while(!pq.empty()){
        auto x = pq.top();
        pq.pop();
        ll d = x.first;
        int now = x.second.first;
        int used = x.second.second;
        if(dst[used][now]!=d)continue;
        for(auto ed: g[now]){
            int next = ed.first;
            ll p = ed.second;
            if(dst[used][next] > d+p){
                dst[used][next] = d+p;
                pq.push(MP(d+p,MP(next,used)));
            }   
            if(used==0){
                if(dst[used+1][next] > d){
                    dst[used+1][next] = d;
                    pq.push(MP(d,MP(next,used+1)));
                }   
            }
        }
    }
    cout << 0 << endl;
    for(int i=1;i<n;i++){
        cout << dst[0][i] + dst[1][i] << endl;
    }
    return 0;
}
0