結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 3 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 3 ms
4,348 KB
testcase_06 AC 3 ms
4,348 KB
testcase_07 AC 3 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
権限があれば一括ダウンロードができます

ソースコード

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][10010];

    for(int i=0;i<10010;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