結果

問題 No.807 umg tours
ユーザー dsaito11dsaito11
提出日時 2019-08-06 17:48:53
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,999 bytes
コンパイル時間 1,330 ms
コンパイル使用メモリ 93,344 KB
実行使用メモリ 17,260 KB
最終ジャッジ日時 2023-09-25 18:00:14
合計ジャッジ時間 7,212 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
7,228 KB
testcase_01 AC 5 ms
7,216 KB
testcase_02 AC 5 ms
7,264 KB
testcase_03 AC 5 ms
7,228 KB
testcase_04 AC 5 ms
7,212 KB
testcase_05 AC 5 ms
7,252 KB
testcase_06 AC 6 ms
7,420 KB
testcase_07 AC 5 ms
7,256 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 298 ms
17,176 KB
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

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 100000000
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;
typedef pair<int, int> P;

typedef struct edge{
   int to;
   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