結果

問題 No.1320 Two Type Min Cost Cycle
ユーザー KudeKude
提出日時 2020-12-17 12:14:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,563 bytes
コンパイル時間 2,417 ms
コンパイル使用メモリ 212,712 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-20 11:24:41
合計ジャッジ時間 10,196 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 5 ms
4,348 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 5 ms
4,348 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 5 ms
4,348 KB
testcase_15 AC 5 ms
4,348 KB
testcase_16 WA -
testcase_17 AC 4 ms
4,348 KB
testcase_18 AC 4 ms
4,348 KB
testcase_19 WA -
testcase_20 AC 3 ms
4,348 KB
testcase_21 AC 148 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 2 ms
4,348 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 WA -
testcase_38 AC 2 ms
4,348 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 2 ms
4,348 KB
testcase_42 AC 2 ms
4,348 KB
testcase_43 AC 6 ms
4,348 KB
testcase_44 AC 4 ms
4,348 KB
testcase_45 WA -
testcase_46 AC 8 ms
4,348 KB
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 AC 2 ms
4,348 KB
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 TLE -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T, n, m;
    cin >> T >> n >> m;
    vector<vector<P>> to(n);
    rep(_, m) {
        int u, v, w;
        cin >> u >> v >> w;
        --u, --v;
        to[u].emplace_back(v, w);
        if (T == 0) to[v].emplace_back(u, w);
    }
    constexpr ll inf = 1002003004005006007;
    ll ans = inf;
    rep(s, n) {
        VI first_move(n);
        VL dist(n, inf);
        priority_queue<P, vector<P>, greater<P>> q;
        auto push = [&](int v, ll c) {
            if (c < dist[v]) {
                first_move[v] = false;
                dist[v] = c;
                q.emplace(c, v);
            }
        };
        for(auto [v, w]: to[s]) {
            push(v, w);
            first_move[v] = true;
        }
        while(!q.empty()) {
            auto [c, u] = q.top(); q.pop();
            if (c != dist[u]) continue;
            for(auto [v, w]: to[u]) {
                if (first_move[u] && v == s) continue;
                push(v, c + w);
            }
        }
        chmin(ans, dist[s]);
    }
    if (ans == inf) ans = -1;
    cout << ans << endl;
}
0