結果

問題 No.2477 Drifting
ユーザー 👑 rin204rin204
提出日時 2023-09-08 19:17:20
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 480 ms / 2,000 ms
コード長 1,221 bytes
コンパイル時間 3,314 ms
コンパイル使用メモリ 269,220 KB
実行使用メモリ 32,712 KB
最終ジャッジ日時 2023-09-08 20:18:35
合計ジャッジ時間 9,423 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 358 ms
32,596 KB
testcase_01 AC 251 ms
22,780 KB
testcase_02 AC 370 ms
32,712 KB
testcase_03 AC 330 ms
14,512 KB
testcase_04 AC 139 ms
9,616 KB
testcase_05 AC 298 ms
13,196 KB
testcase_06 AC 464 ms
30,356 KB
testcase_07 AC 480 ms
30,436 KB
testcase_08 AC 359 ms
25,896 KB
testcase_09 AC 207 ms
26,056 KB
testcase_10 AC 215 ms
29,140 KB
testcase_11 AC 203 ms
23,504 KB
testcase_12 AC 253 ms
23,688 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 197 ms
22,180 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<pair<int, ll>>> edges(n);
    for (int i = 0; i < m; i++) {
        int u, v;
        ll w;
        cin >> u >> v >> w;
        edges[u - 1].emplace_back(v - 1, w);
    }
    int k;
    cin >> k;
    vector<set<pair<int, int>>> ng(n);
    for (int i = 0; i < k; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        ng[b - 1].emplace(a - 1, c - 1);
    }

    vector<vector<pair<ll, int>>> cand(n, vector<pair<ll, int>>());
    cand[0].emplace_back(0, 0);
    for (int l = 0; l < n; l++) {
        sort(cand[l].begin(), cand[l].end());
        for (auto [d, a] : cand[l]) {
            vector<pair<int, ll>> nedges;
            for (auto [r, w] : edges[l]) {
                if (ng[l].count({a, r})) {
                    nedges.emplace_back(r, w);
                } else {
                    cand[r].emplace_back(d + w, l);
                }
            }
            edges[l] = nedges;
        }
    }

    const ll inf = 1LL << 60;
    ll ans       = inf;
    for (auto [d, _] : cand[n - 1]) {
        ans = min(ans, d);
    }
    cout << (ans == inf ? -1 : ans) << endl;
}
0