結果

問題 No.807 umg tours
ユーザー Y17Y17
提出日時 2019-03-22 22:21:31
言語 C++11
(gcc 11.4.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,464 bytes
コンパイル時間 1,373 ms
コンパイル使用メモリ 155,668 KB
実行使用メモリ 22,728 KB
最終ジャッジ日時 2023-08-15 12:03:10
合計ジャッジ時間 12,327 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,756 KB
testcase_01 AC 4 ms
5,852 KB
testcase_02 AC 4 ms
5,764 KB
testcase_03 AC 4 ms
5,728 KB
testcase_04 AC 4 ms
5,724 KB
testcase_05 AC 4 ms
5,676 KB
testcase_06 AC 5 ms
5,808 KB
testcase_07 AC 4 ms
5,696 KB
testcase_08 AC 4 ms
5,688 KB
testcase_09 AC 3 ms
5,732 KB
testcase_10 AC 4 ms
5,744 KB
testcase_11 AC 280 ms
16,660 KB
testcase_12 AC 299 ms
13,864 KB
testcase_13 AC 388 ms
16,872 KB
testcase_14 AC 172 ms
10,540 KB
testcase_15 AC 130 ms
9,436 KB
testcase_16 AC 414 ms
17,576 KB
testcase_17 AC 532 ms
21,712 KB
testcase_18 AC 526 ms
22,472 KB
testcase_19 AC 507 ms
19,020 KB
testcase_20 AC 296 ms
12,420 KB
testcase_21 AC 305 ms
12,564 KB
testcase_22 AC 127 ms
8,684 KB
testcase_23 AC 102 ms
8,040 KB
testcase_24 TLE -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

vector<pair<int, long long> > graph[100010];

typedef pair<long long, pair<int, int> > P;

long long dist[100010][2];

int main(){
    int n, m;
    cin >> n >> m;

    int a, b;
    long long c;
    for(int i = 0;i < m;i++){
        cin >> a >> b >> c;
        a--, b--;
        graph[a].push_back(make_pair(b, c));
        graph[b].push_back(make_pair(a, c));
    }

    dist[0][1] = 0;
    dist[0][0] = 0;
    for(int i = 1;i < n;i++){
        dist[i][0] = dist[i][1] = LLONG_MAX;
    }

    priority_queue<P, vector<P>, greater<P> > que;

    que.push(make_pair(0, make_pair(0, 1)));
    que.push(make_pair(0, make_pair(0, 0)));

    while(!que.empty()){
        long long cost = que.top().first;
        int idx = que.top().second.first;
        int tk = que.top().second.second;
        que.pop();

        for(int i = 0;i < graph[idx].size();i++){
            int next = graph[idx][i].first;
            long long ncost = graph[idx][i].second;
            if(cost + ncost < dist[next][tk]){
                dist[next][tk] = cost + ncost;
                que.push(make_pair(dist[next][tk], make_pair(next, tk)));
            }
            if(tk == 1 && cost < dist[next][0]){
                dist[next][0] = cost;
                que.push(make_pair(cost, make_pair(next, 0)));
            }
        }
    }

    for(int i = 0;i < n;i++){
        cout << dist[i][1] + dist[i][0] << endl;
    }

    return 0;
}

0