結果

問題 No.468 役に立つ競技プログラミング実践編
ユーザー kyunakyuna
提出日時 2019-10-25 15:15:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 339 ms / 2,000 ms
コード長 2,026 bytes
コンパイル時間 929 ms
コンパイル使用メモリ 92,352 KB
実行使用メモリ 24,708 KB
最終ジャッジ日時 2023-09-27 01:53:21
合計ジャッジ時間 8,159 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,388 KB
testcase_14 AC 4 ms
4,380 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 4 ms
4,376 KB
testcase_17 AC 4 ms
4,380 KB
testcase_18 AC 4 ms
4,376 KB
testcase_19 AC 3 ms
4,380 KB
testcase_20 AC 4 ms
4,380 KB
testcase_21 AC 4 ms
4,376 KB
testcase_22 AC 3 ms
4,380 KB
testcase_23 AC 4 ms
4,384 KB
testcase_24 AC 334 ms
24,676 KB
testcase_25 AC 339 ms
24,576 KB
testcase_26 AC 336 ms
24,588 KB
testcase_27 AC 336 ms
24,584 KB
testcase_28 AC 337 ms
24,536 KB
testcase_29 AC 329 ms
24,644 KB
testcase_30 AC 337 ms
24,708 KB
testcase_31 AC 335 ms
24,576 KB
testcase_32 AC 332 ms
24,568 KB
testcase_33 AC 335 ms
24,560 KB
testcase_34 AC 93 ms
16,012 KB
testcase_35 AC 2 ms
4,384 KB
testcase_36 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <tuple>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using edge = pair<int, long long>;
using Graph = vector<vector<edge>>;

int main() {
    int n, m; cin >> n >> m;
    Graph gg(n), rg(n);
    while (m--) {
        int a, b, c; cin >> a >> b >> c;
        gg[a].emplace_back(b, c);
        rg[b].emplace_back(a, c);
    }
    auto early = [&](const Graph &g, int s) {
        vector<long long> dist(g.size(), 0);
        using Pi = pair<long long, int>;
        priority_queue<Pi> que;
        dist[s] = 0; que.emplace(dist[s], s);
        vector<int> done(g.size());
        while (!que.empty()) {
            long long cost; int u; tie(cost, u) = que.top(); que.pop();
            for (auto &e: g[u]) {
                int v; long long nc; tie(v, nc) = e;
                chmax(dist[v], dist[u] + nc);
                if (++done[v] == rg[v].size()) que.emplace(dist[v], v);
            }
        }
        return dist;
    }(gg, 0);
    long long critical = early[n - 1];
    auto late = [&](const Graph &g, int s) {
        vector<long long> dist(g.size(), critical);
        using Pi = pair<long long, int>;
        priority_queue<Pi, vector<Pi>, greater<Pi>> que;
        dist[s] = critical; que.emplace(dist[s], s);
        vector<int> done(g.size());
        while (!que.empty()) {
            long long cost; int u; tie(cost, u) = que.top(); que.pop();
            for (auto &e: g[u]) {
                int v; long long nc; tie(v, nc) = e;
                chmin(dist[v], dist[u] - nc);
                if (++done[v] == gg[v].size()) que.emplace(dist[v], v);
            }
        }
        return dist;
    }(rg, n - 1);
    int cnt = 0;
    for (int i = 0; i < n; i++) cnt += early[i] < late[i];
    cout << critical << " " << cnt << "/" << n << endl;
    return 0;
}
0