結果

問題 No.807 umg tours
ユーザー amesyuamesyu
提出日時 2020-02-01 14:36:58
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,779 bytes
コンパイル時間 1,091 ms
コンパイル使用メモリ 82,748 KB
実行使用メモリ 24,392 KB
最終ジャッジ日時 2024-09-18 20:01:04
合計ジャッジ時間 8,132 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 22 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

    for(long long 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(long long 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;
        long long int point =  q.second.second;
        long long int ticket = q.second.first;
        if(cost > ans[ticket][point]) continue;

        for(int i=0;i<graph[point].size();i++) {
            long long int to1 = graph[point][i].to;
            long long 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(long long int i=0;i<n;i++) {
        cout << ans[0][i]+ans[1][i] << endl;
    }
}
//拡張ダイクストラXD
0