結果

問題 No.2477 Drifting
ユーザー だれだれ
提出日時 2023-09-07 00:35:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 357 ms / 2,000 ms
コード長 1,441 bytes
コンパイル時間 1,181 ms
コンパイル使用メモリ 108,040 KB
実行使用メモリ 36,784 KB
最終ジャッジ日時 2023-09-08 20:17:38
合計ジャッジ時間 5,657 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 264 ms
33,860 KB
testcase_01 AC 157 ms
23,248 KB
testcase_02 AC 253 ms
33,684 KB
testcase_03 AC 214 ms
18,228 KB
testcase_04 AC 94 ms
11,232 KB
testcase_05 AC 231 ms
16,540 KB
testcase_06 AC 355 ms
36,720 KB
testcase_07 AC 357 ms
36,784 KB
testcase_08 AC 277 ms
31,568 KB
testcase_09 AC 128 ms
27,172 KB
testcase_10 AC 133 ms
29,908 KB
testcase_11 AC 130 ms
24,320 KB
testcase_12 AC 149 ms
28,996 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 118 ms
23,772 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <array>
#include <iostream>
#include <set>
#include <vector>

using namespace std;
using i64 = long long;

using A = array<int, 3>;

A make(int a, int b, int c) {
    A res;
    res[0] = a;
    res[1] = b;
    res[2] = c;
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<set<pair<int, i64>>> out(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        i64 w;
        cin >> a >> b >> w;
        a--, b--;
        out[a].emplace(b, w);
    }
    set<A> banned;
    int k;
    cin >> k;
    for (int i = 0; i < k; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        a--, b--, c--;
        banned.emplace(make(a, b, c));
    }
    vector<vector<pair<i64, int>>> in(n);
    vector<i64> dist(n, 1e18);
    in[0].emplace_back(0, -1);
    for (int i = 0; i < n; i++) {
        auto& v = in[i];
        sort(v.begin(), v.end());
        vector<pair<int, int>> er;
        for (auto& [c, from] : v) {
            dist[i] = min(dist[i], c);
            for (auto& [to, w] : out[i]) {
                if (banned.count(make(from, i, to))) continue;
                in[to].emplace_back(c + w, i);
                er.emplace_back(to, w);
            }
            for (auto p : er) out[i].erase(p);
            er.clear();
        }
    }
    i64 ans = dist[n - 1];
    if (ans == 1e18) ans = -1;
    cout << ans << endl;
}
0