結果

問題 No.468 役に立つ競技プログラミング実践編
ユーザー kyunakyuna
提出日時 2019-10-25 15:47:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 324 ms / 2,000 ms
コード長 1,606 bytes
コンパイル時間 900 ms
コンパイル使用メモリ 88,796 KB
実行使用メモリ 30,268 KB
最終ジャッジ日時 2023-09-27 07:22:47
合計ジャッジ時間 7,334 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 4 ms
4,380 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 4 ms
4,376 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 4 ms
4,376 KB
testcase_21 AC 4 ms
4,376 KB
testcase_22 AC 4 ms
4,376 KB
testcase_23 AC 4 ms
4,380 KB
testcase_24 AC 323 ms
30,004 KB
testcase_25 AC 320 ms
30,120 KB
testcase_26 AC 322 ms
30,048 KB
testcase_27 AC 315 ms
30,104 KB
testcase_28 AC 308 ms
30,136 KB
testcase_29 AC 307 ms
30,196 KB
testcase_30 AC 317 ms
30,096 KB
testcase_31 AC 324 ms
30,004 KB
testcase_32 AC 315 ms
30,116 KB
testcase_33 AC 315 ms
30,268 KB
testcase_34 AC 98 ms
21,296 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using Graph = vector<vector<int>>;
vector<int> tsort(Graph &g) {
    int n = g.size(), k = 0;
    vector<int> ord(n), in(n);
    for (int u = 0; u < n; u++) for (int v: g[u]) in[v]++;
    queue<int> que;
    for (int u = 0; u < n; u++) if (in[u] == 0) que.push(u);
    while (!que.empty()) {
        int u = que.front(); que.pop();
        ord[k++] = u;
        for (int v: g[u]) if (--in[v] == 0) que.push(v);
    }
    return *max_element(in.begin(), in.end()) == 0 ? ord : vector<int>();
}

using edge = pair<int, long long>;
using graph = vector<vector<edge>>;
int main() {
    int n, m; cin >> n >> m;
    Graph g(n);
    graph gg(n), rg(n);
    while (m--) {
        int a, b, c; cin >> a >> b >> c;
        g[a].emplace_back(b);
        gg[a].emplace_back(b, c);
        rg[b].emplace_back(a, c);
    }
    auto ord = tsort(g);
    vector<long long> dp(n);
    for (int u: ord) for (auto &p: gg[u]) {
        int v = p.first; long long c = p.second;
        chmax(dp[v], dp[u] + c);
    }
    long long typical = dp.back();
    reverse(ord.begin(), ord.end());
    vector<int> on_typ(n); on_typ.back() = true;
    for (int v: ord) if (on_typ[v]) for (auto &p: rg[v]) {
        int u = p.first; long long c = p.second;
        if (dp[u] + c == dp[v]) on_typ[u] |= on_typ[v];
    }
    int cnt = count(on_typ.begin(), on_typ.end(), false);
    cout << typical << " " << cnt << "/" << n << endl;
    return 0;
}
0