結果

問題 No.2477 Drifting
ユーザー だれだれ
提出日時 2023-09-06 15:28:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,336 bytes
コンパイル時間 1,208 ms
コンパイル使用メモリ 107,832 KB
実行使用メモリ 36,800 KB
最終ジャッジ日時 2023-09-08 20:17:55
合計ジャッジ時間 8,166 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 464 ms
33,468 KB
testcase_01 AC 286 ms
23,572 KB
testcase_02 AC 460 ms
33,576 KB
testcase_03 AC 344 ms
18,332 KB
testcase_04 AC 137 ms
11,148 KB
testcase_05 AC 307 ms
16,220 KB
testcase_06 AC 590 ms
36,800 KB
testcase_07 AC 580 ms
36,764 KB
testcase_08 AC 460 ms
31,480 KB
testcase_09 AC 254 ms
27,256 KB
testcase_10 AC 256 ms
30,024 KB
testcase_11 AC 247 ms
24,064 KB
testcase_12 WA -
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 WA -
testcase_16 AC 236 ms
23,684 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() {
    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();
        }
    }
    cout << dist[n - 1] << endl;
}
0