結果

問題 No.807 umg tours
ユーザー Y17Y17
提出日時 2019-03-22 22:21:31
言語 C++11
(gcc 11.4.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,464 bytes
コンパイル時間 1,710 ms
コンパイル使用メモリ 169,308 KB
実行使用メモリ 22,912 KB
最終ジャッジ日時 2024-05-02 23:28:42
合計ジャッジ時間 12,617 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,760 KB
testcase_01 AC 3 ms
5,888 KB
testcase_02 AC 4 ms
5,888 KB
testcase_03 AC 3 ms
5,888 KB
testcase_04 AC 3 ms
5,760 KB
testcase_05 AC 3 ms
5,760 KB
testcase_06 AC 4 ms
5,888 KB
testcase_07 AC 4 ms
5,888 KB
testcase_08 AC 3 ms
5,760 KB
testcase_09 AC 4 ms
5,760 KB
testcase_10 AC 3 ms
5,760 KB
testcase_11 AC 300 ms
16,788 KB
testcase_12 AC 294 ms
14,272 KB
testcase_13 AC 416 ms
17,080 KB
testcase_14 AC 179 ms
10,796 KB
testcase_15 AC 134 ms
9,344 KB
testcase_16 AC 430 ms
17,752 KB
testcase_17 AC 532 ms
21,032 KB
testcase_18 AC 547 ms
21,212 KB
testcase_19 AC 557 ms
19,192 KB
testcase_20 AC 321 ms
12,544 KB
testcase_21 AC 327 ms
12,800 KB
testcase_22 AC 130 ms
8,720 KB
testcase_23 AC 102 ms
8,192 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