結果

問題 No.807 umg tours
ユーザー veqccveqcc
提出日時 2019-03-22 22:08:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,004 bytes
コンパイル時間 1,228 ms
コンパイル使用メモリ 113,436 KB
実行使用メモリ 16,764 KB
最終ジャッジ日時 2023-10-19 09:20:32
合計ジャッジ時間 4,086 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,544 KB
testcase_01 AC 3 ms
6,544 KB
testcase_02 AC 3 ms
6,568 KB
testcase_03 AC 4 ms
6,560 KB
testcase_04 AC 4 ms
6,536 KB
testcase_05 AC 4 ms
6,544 KB
testcase_06 AC 3 ms
6,572 KB
testcase_07 AC 4 ms
6,560 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 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 18;

struct edge {
    int to;
    ll cost;
};

typedef pair <int, int> P;
typedef pair <ll, P> PP;
int V, E;
vector <edge> G[100005];
int d[2][100005];
// 0: チケットを使わない最短距離
// 1: チケットを1回使った時の最短距離

void dijkstra(int s) {
    priority_queue<PP, vector<PP>, greater<PP>> q;
    fill(d[0], d[1]+V, INF);
    d[0][s] = d[1][s] = 0;
    q.push(PP(0LL, P(s, 0)));

    while (!q.empty()) {
        PP p = q.top();
        q.pop();

        int cost = p.first;
        int cur = p.second.first;
        int used = p.second.second;

        if (d[used][cur] < cost) continue;

        for (edge e : G[cur]) {
            if (used == 1) {
                if (d[1][e.to] > d[1][cur] + e.cost) {
                    d[1][e.to] = d[1][cur] + e.cost;
                    q.push(PP(d[1][e.to], P(e.to, 1)));
                }
            } else {
                if (d[0][e.to] > d[0][cur] + e.cost) {
                    d[0][e.to] = d[0][cur] + e.cost;
                    q.push(PP(d[0][e.to], P(e.to, 0)));
                }

                if (d[1][e.to] > d[0][cur]) {
                    d[1][e.to] = d[0][cur];
                    q.push(PP(d[1][e.to], P(e.to, 1)));
                }
            }
        }
    }
}

int main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> V >> E;

    for (int i = 0; i < E; i++) {
        int a, b;
        ll c;
        cin >> a >> b >> c;
        a--; b--;
        G[a].push_back((edge){b, c});
        G[b].push_back((edge){a, c});
    }

    dijkstra(0);

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

    return 0;
}
0