結果

問題 No.807 umg tours
ユーザー amesyuamesyu
提出日時 2020-02-01 14:34:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,659 bytes
コンパイル時間 838 ms
コンパイル使用メモリ 82,356 KB
実行使用メモリ 22,220 KB
最終ジャッジ日時 2023-10-19 00:00:42
合計ジャッジ時間 7,136 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,268 KB
testcase_01 AC 3 ms
5,268 KB
testcase_02 AC 3 ms
5,292 KB
testcase_03 AC 3 ms
5,284 KB
testcase_04 AC 3 ms
5,260 KB
testcase_05 AC 3 ms
5,268 KB
testcase_06 AC 4 ms
5,296 KB
testcase_07 AC 4 ms
5,284 KB
testcase_08 AC 3 ms
5,244 KB
testcase_09 AC 3 ms
5,244 KB
testcase_10 AC 3 ms
5,256 KB
testcase_11 AC 287 ms
16,332 KB
testcase_12 AC 291 ms
13,972 KB
testcase_13 AC 392 ms
16,964 KB
testcase_14 AC 170 ms
10,380 KB
testcase_15 AC 134 ms
9,104 KB
testcase_16 AC 404 ms
17,640 KB
testcase_17 AC 513 ms
22,172 KB
testcase_18 AC 508 ms
22,220 KB
testcase_19 AC 497 ms
19,292 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 299 ms
19,728 KB
testcase_25 AC 506 ms
21,756 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
using namespace std;
#define INF 1000000000
typedef pair<int, int> P;
typedef pair<long long int, P> T;
typedef struct edge {
    int to;
    long long int cost;
} edge;

int main() {
    int n, m;
    int a, b, c;
    cin >> n >> m;
    vector<edge> graph[n];
    long long int ans[2][100010];

    for(int i=0;i<100010;i++) {
        ans[0][i] = INF;
        ans[1][i] = INF;
    }

    ans[0][0] = 0;
    ans[1][0] = 0;
    edge e;
    for(int i=0;i<m;i++) {
        cin >> a >> b >> c;
        e.to = b-1;  e.cost = c;
        graph[a-1].push_back(e);
        e.to = a-1;  e.cost = c;
        graph[b-1].push_back(e);
    }
    priority_queue < T, vector<T>, greater<T> > que;
    que.push(T(0, P(1, 0)));
    while(!que.empty()) {
        T q = que.top();
        que.pop();

        long long cost = q.first;
        int point =  q.second.second;
        int ticket = q.second.first;
        if(cost > ans[ticket][point]) continue;

        for(int i=0;i<graph[point].size();i++) {
            int to1 = graph[point][i].to;
            int cost1 = graph[point][i].cost;

            if(ticket == 1) {
                if(cost < ans[0][to1]) {
                    que.push(T(cost, P(0, to1)));
                    ans[0][to1] = cost;
                }
            }

            if(cost1+cost < ans[ticket][to1]) {
                que.push(T(cost1+cost, P(ticket, to1)));
                ans[ticket][to1] = cost1+cost;
            } 
        }

    }
    for(int i=0;i<n;i++) {
        cout << ans[0][i]+ans[1][i] << endl;
    }
}
//拡張ダイクストラXD
0