結果

問題 No.807 umg tours
ユーザー yuji9511yuji9511
提出日時 2019-03-22 22:55:56
言語 C++11
(gcc 11.4.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,891 bytes
コンパイル時間 1,943 ms
コンパイル使用メモリ 165,104 KB
実行使用メモリ 25,148 KB
最終ジャッジ日時 2024-05-02 23:30:16
合計ジャッジ時間 12,160 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
9,600 KB
testcase_01 AC 7 ms
9,600 KB
testcase_02 AC 7 ms
9,728 KB
testcase_03 AC 7 ms
9,600 KB
testcase_04 AC 7 ms
9,600 KB
testcase_05 AC 6 ms
9,600 KB
testcase_06 AC 8 ms
9,728 KB
testcase_07 AC 7 ms
9,600 KB
testcase_08 AC 7 ms
9,472 KB
testcase_09 AC 6 ms
9,600 KB
testcase_10 AC 7 ms
9,600 KB
testcase_11 AC 177 ms
20,224 KB
testcase_12 AC 221 ms
17,036 KB
testcase_13 AC 299 ms
21,912 KB
testcase_14 AC 123 ms
14,008 KB
testcase_15 AC 103 ms
13,248 KB
testcase_16 AC 328 ms
22,568 KB
testcase_17 AC 417 ms
23,408 KB
testcase_18 AC 405 ms
23,316 KB
testcase_19 AC 420 ms
23,604 KB
testcase_20 AC 261 ms
16,320 KB
testcase_21 AC 285 ms
16,640 KB
testcase_22 AC 111 ms
12,756 KB
testcase_23 AC 86 ms
12,168 KB
testcase_24 TLE -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
typedef pair<ll, lpair> lpair2;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,M;
    cin >> N >> M;
    ll A[100010], B[100010], C[100010];
    vector<lpair> tree[100010];
    rep(i,0,M){
        cin >> A[i] >> B[i] >> C[i];
        A[i]--; B[i]--;
        tree[A[i]].push_back(make_pair(B[i], C[i]));
        tree[B[i]].push_back(make_pair(A[i], C[i]));
    }
    ll dist1[100010] = {};
    rep(i,1,N) dist1[i] = INF;
    priority_queue<lpair, vector<lpair>, greater<lpair> > pq;
    rep(i,0,N) pq.push(make_pair(dist1[i], i));
    while(!pq.empty()){
        lpair l1 = pq.top();
        pq.pop();
        ll cur = l1.second;
        for(auto &e: tree[cur]){
            if(dist1[e.first] > dist1[cur] + e.second){
                dist1[e.first] = dist1[cur] + e.second;
                pq.push(make_pair(dist1[e.first], e.first));
            }
        }
    }
    ll dist2[100010] = {};
    rep(i,1,N) dist2[i] = INF;
    priority_queue<lpair, vector<lpair>, greater<lpair> > pq2;
    rep(i,0,N) pq.push(make_pair(dist2[i], i));
    while(!pq.empty()){
        lpair l1 = pq.top();
        pq.pop();
        ll cur = l1.second;
        for(auto &e: tree[cur]){
            ll v = min(dist2[cur] + e.second, dist1[cur]);
            if(dist2[e.first] > v){
                dist2[e.first] = v;
                pq.push(make_pair(dist2[e.first], e.first));
            }
        }
    }
    rep(i,0,N){
        print(dist1[i] + dist2[i]);
    }    
}
0