結果

問題 No.807 umg tours
ユーザー dsaito11dsaito11
提出日時 2019-08-06 17:59:18
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 536 ms / 4,000 ms
コード長 2,012 bytes
コンパイル時間 2,155 ms
コンパイル使用メモリ 94,016 KB
実行使用メモリ 21,340 KB
最終ジャッジ日時 2024-05-02 23:58:09
合計ジャッジ時間 7,849 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,360 KB
testcase_01 AC 5 ms
7,364 KB
testcase_02 AC 4 ms
7,104 KB
testcase_03 AC 4 ms
7,240 KB
testcase_04 AC 4 ms
7,240 KB
testcase_05 AC 4 ms
7,296 KB
testcase_06 AC 5 ms
7,424 KB
testcase_07 AC 5 ms
7,232 KB
testcase_08 AC 4 ms
7,364 KB
testcase_09 AC 5 ms
7,364 KB
testcase_10 AC 5 ms
7,168 KB
testcase_11 AC 298 ms
17,876 KB
testcase_12 AC 308 ms
14,572 KB
testcase_13 AC 399 ms
17,500 KB
testcase_14 AC 173 ms
11,896 KB
testcase_15 AC 135 ms
10,436 KB
testcase_16 AC 422 ms
18,152 KB
testcase_17 AC 536 ms
21,292 KB
testcase_18 AC 518 ms
21,340 KB
testcase_19 AC 513 ms
19,188 KB
testcase_20 AC 314 ms
12,544 KB
testcase_21 AC 332 ms
12,860 KB
testcase_22 AC 134 ms
9,616 KB
testcase_23 AC 107 ms
9,156 KB
testcase_24 AC 310 ms
17,664 KB
testcase_25 AC 531 ms
21,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//#include <bits/stdc++.h>

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>

#define INF 100000000000
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;
typedef pair<int, int> P;

typedef struct edge{
   int to;
   long long int cost;
} edge;

vector<edge> graph[100010];
long long int d[2][100010];

void dijkstra(int s){
    typedef pair<long long int, P> T; //pair<頂点までの距離, チケット残り, 頂点>
    priority_queue<T, vector<T>, greater<T> > que;
    for(int i = 0; i < 100010; i++){
        d[0][i] = INF;
        d[1][i] = INF;
    }
    d[1][s] = 0;
    d[0][s] = 0;
    que.push(T(0, P(1, s)));
    que.push(T(0, P(0, s)));

    while(!que.empty()){
        T t = que.top();
        que.pop();
        long long int dist = t.first;
        int state = t.second.first;
        int v = t.second.second;

        if(dist > d[state][v]) continue;

        for(int i = 0; i < graph[v].size(); i++){
            edge e = graph[v][i];
            if(d[state][e.to] > dist + e.cost){
                d[state][e.to] = dist + e.cost;
                que.push(T(d[state][e.to], P(state, e.to)));
            }
        }

        if(state == 1){
            for(int i = 0; i < graph[v].size(); i++){
                edge e = graph[v][i];
                if(d[0][e.to] > dist + 0){
                    d[0][e.to] = dist + 0;
                    que.push(T(d[0][e.to], P(0, e.to)));
                }
            }
        }
    }
}


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

    for(int i = 0; i < m; i++){
        int s, t;
        long long int c;
        cin >> s >> t >> c;
        s--;
        t--;

        edge e;
        e.to = t; e.cost = c; graph[s].push_back(e);
        e.to = s; e.cost = c; graph[t].push_back(e);
    }

    dijkstra(0);

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