結果

問題 No.468 役に立つ競技プログラミング実践編
ユーザー pekempeypekempey
提出日時 2016-12-18 00:12:12
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 135 ms / 2,000 ms
コード長 853 bytes
コンパイル時間 1,838 ms
コンパイル使用メモリ 168,200 KB
実行使用メモリ 14,128 KB
最終ジャッジ日時 2023-08-20 22:05:01
合計ジャッジ時間 5,467 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,812 KB
testcase_01 AC 4 ms
5,696 KB
testcase_02 AC 3 ms
5,700 KB
testcase_03 AC 4 ms
5,872 KB
testcase_04 AC 4 ms
6,024 KB
testcase_05 AC 4 ms
5,912 KB
testcase_06 AC 4 ms
5,944 KB
testcase_07 AC 4 ms
5,752 KB
testcase_08 AC 4 ms
5,948 KB
testcase_09 AC 3 ms
5,700 KB
testcase_10 AC 4 ms
5,704 KB
testcase_11 AC 4 ms
5,796 KB
testcase_12 AC 3 ms
5,688 KB
testcase_13 AC 4 ms
5,796 KB
testcase_14 AC 5 ms
6,044 KB
testcase_15 AC 5 ms
5,856 KB
testcase_16 AC 5 ms
5,768 KB
testcase_17 AC 4 ms
5,960 KB
testcase_18 AC 4 ms
5,860 KB
testcase_19 AC 5 ms
6,092 KB
testcase_20 AC 5 ms
5,744 KB
testcase_21 AC 5 ms
5,828 KB
testcase_22 AC 4 ms
5,708 KB
testcase_23 AC 5 ms
5,852 KB
testcase_24 AC 128 ms
11,636 KB
testcase_25 AC 129 ms
11,720 KB
testcase_26 AC 129 ms
11,520 KB
testcase_27 AC 132 ms
11,732 KB
testcase_28 AC 135 ms
11,648 KB
testcase_29 AC 128 ms
11,768 KB
testcase_30 AC 128 ms
11,860 KB
testcase_31 AC 128 ms
11,712 KB
testcase_32 AC 129 ms
11,632 KB
testcase_33 AC 128 ms
11,760 KB
testcase_34 AC 43 ms
14,128 KB
testcase_35 AC 4 ms
5,916 KB
testcase_36 AC 4 ms
5,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

struct Edge {
    int v;
    int w;
};

vector<Edge> g[100000];

int cost[100000];
bool vis[100000];

void dfs(int u) {
    if (cost[u] != 0) {
        return;
    }
    for (Edge e : g[u]) {
        dfs(e.v);
        cost[u] = max(cost[u], cost[e.v] + e.w);
    }
}

void dfs2(int u) {
    if (vis[u]) {
        return;
    }
    vis[u] = true;
    for (Edge e : g[u]) {
        if (cost[u] == cost[e.v] + e.w) {
            dfs2(e.v);
        }
    }
}

int main() {
    int n, m;
    cin >> n >> m;

    for (int i = 0; i < m; i++) {
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);
        g[a].push_back({ b, c });
    }
    dfs(0);
    dfs2(0);

    int cnt = 0;
    for (int i = 0; i < n; i++) {
        cnt += vis[i];
    }
    cout << cost[0] << " " << (n - cnt) << "/" << n << endl;
}
0