結果

問題 No.614 壊れたキャンパス
ユーザー sekiya9311sekiya9311
提出日時 2017-12-14 21:27:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,277 bytes
コンパイル時間 4,852 ms
コンパイル使用メモリ 186,892 KB
実行使用メモリ 48,416 KB
最終ジャッジ日時 2023-08-21 04:44:26
合計ジャッジ時間 7,361 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
23,412 KB
testcase_01 AC 9 ms
19,028 KB
testcase_02 AC 9 ms
19,008 KB
testcase_03 AC 8 ms
19,004 KB
testcase_04 AC 8 ms
19,024 KB
testcase_05 AC 10 ms
19,036 KB
testcase_06 AC 10 ms
19,020 KB
testcase_07 AC 8 ms
19,004 KB
testcase_08 AC 626 ms
31,984 KB
testcase_09 AC 182 ms
35,840 KB
testcase_10 AC 115 ms
24,232 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using state = tuple<long long, int, int>;   // (cost, tou, kai)

const int MAX = 2e5 + 10;
int N, M, S, T;
long K;
vector<pair<int, long long>> G[MAX];
unordered_map<int, long long> mp[MAX];   //[tou][kai] = minCost

int main() {
    scanf("%d%d%lld%d%d", &N, &M, &K, &S, &T);
    S--;T--;K--;
    for (int i = 0; i < M; i++) {
        int a, b, c;
        scanf("%d%d%d", &a, &b, &c);
        a--;b--;c--;
        G[a].emplace_back(b, c);
    }
    priority_queue<state, vector<state>, greater<state>> pq;
    pq.emplace(0, 0, S);
    const long long inf = 1e18;
    long long ans = inf;
    while (!pq.empty()) {
        long long cost;
        int tou, kai;
        tie(cost, tou, kai) = pq.top();
        pq.pop();
        if (tou == N - 1) {
            ans = min(ans, cost + llabs(kai - T));
        }
        if (mp[tou].count(kai)) {
            continue;
        }
        mp[tou][kai] = cost;
        for (auto&& e : G[tou]) {
            if (mp[tou + 1].count(e.second) && mp[tou + 1][e.second] <= cost + llabs(e.first - kai)) {
                continue;
            }
            pq.emplace(cost + llabs(e.first - kai), tou + 1, e.second);
        }
    }
    cout << (ans == inf ? -1 : ans) << endl;
    return 0;
}
0