結果

問題 No.2477 Drifting
ユーザー りあんりあん
提出日時 2023-09-11 20:17:09
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 251 ms / 2,000 ms
コード長 1,684 bytes
コンパイル時間 6,534 ms
コンパイル使用メモリ 281,356 KB
実行使用メモリ 35,324 KB
最終ジャッジ日時 2023-09-11 20:17:20
合計ジャッジ時間 9,005 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 245 ms
35,288 KB
testcase_01 AC 152 ms
24,272 KB
testcase_02 AC 245 ms
35,324 KB
testcase_03 AC 191 ms
13,956 KB
testcase_04 AC 54 ms
8,352 KB
testcase_05 AC 119 ms
11,604 KB
testcase_06 AC 251 ms
33,516 KB
testcase_07 AC 246 ms
33,460 KB
testcase_08 AC 170 ms
25,960 KB
testcase_09 AC 79 ms
16,376 KB
testcase_10 AC 88 ms
18,628 KB
testcase_11 AC 89 ms
16,072 KB
testcase_12 AC 123 ms
20,052 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 68 ms
11,932 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #pragma GCC target("avx2")
#pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;

using P = pair<int, int>;

const int M = 998244353;
const long long LM = 1LL << 60;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    vector<vector<pair<long long, int>>> edge(n);
    for (int i = 0; i < m; ++i) {
        int u, v;
        long long w;
        cin >> u >> v >> w;
        --u;
        --v;
        edge[u].emplace_back(w, v);
    }
    int k;
    cin >> k;
    unordered_map<long long, unordered_set<int>> banned;
    for (int i = 0; i < k; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        --a;
        --b;
        --c;
        if (!banned.count(a * (long long)M + b)) {
            banned[a * (long long)M + b] = unordered_set<int>();
        }
        banned[a * (long long)M + b].insert(c);
    }
    long long ans = -1;
    priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, greater<pair<long long, long long>>> pq;
    pq.emplace(0LL, 0LL);

    while (!pq.empty()) {
        auto p = pq.top();
        pq.pop();
        int now = p.second % M;
        if (now == n - 1) {
            ans = p.first;
            break;
        }
        vector<pair<long long, int>> rem;
        for (auto& e : edge[now]) {
            if (banned.count(p.second) && banned[p.second].count(e.second)) {
                rem.push_back(e);
            }
            else {
                pq.emplace(e.first + p.first, now * (long long)M + e.second);
            }
        }
        edge[now] = rem;
    }

    cout << ans << '\n';

    return 0;
}
0