結果

問題 No.468 役に立つ競技プログラミング実践編
ユーザー nukachanukacha
提出日時 2017-05-05 05:11:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 343 ms / 2,000 ms
コード長 1,790 bytes
コンパイル時間 868 ms
コンパイル使用メモリ 76,312 KB
実行使用メモリ 23,424 KB
最終ジャッジ日時 2023-10-12 09:05:20
合計ジャッジ時間 6,238 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,368 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,368 KB
testcase_03 AC 2 ms
4,368 KB
testcase_04 AC 1 ms
4,372 KB
testcase_05 AC 2 ms
4,372 KB
testcase_06 AC 2 ms
4,368 KB
testcase_07 AC 2 ms
4,368 KB
testcase_08 AC 2 ms
4,368 KB
testcase_09 AC 2 ms
4,372 KB
testcase_10 AC 1 ms
4,372 KB
testcase_11 AC 2 ms
4,368 KB
testcase_12 AC 2 ms
4,372 KB
testcase_13 AC 2 ms
4,368 KB
testcase_14 AC 4 ms
4,368 KB
testcase_15 AC 4 ms
4,368 KB
testcase_16 AC 4 ms
4,368 KB
testcase_17 AC 4 ms
4,368 KB
testcase_18 AC 4 ms
4,368 KB
testcase_19 AC 4 ms
4,368 KB
testcase_20 AC 4 ms
4,368 KB
testcase_21 AC 4 ms
4,368 KB
testcase_22 AC 4 ms
4,372 KB
testcase_23 AC 4 ms
4,372 KB
testcase_24 AC 343 ms
18,560 KB
testcase_25 AC 337 ms
18,740 KB
testcase_26 AC 337 ms
18,880 KB
testcase_27 AC 337 ms
18,936 KB
testcase_28 AC 332 ms
18,892 KB
testcase_29 AC 337 ms
18,856 KB
testcase_30 AC 332 ms
18,672 KB
testcase_31 AC 334 ms
18,556 KB
testcase_32 AC 335 ms
18,600 KB
testcase_33 AC 330 ms
18,748 KB
testcase_34 AC 108 ms
23,424 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 1 ms
4,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <limits>

    int n, m;
    std::vector<std::vector<int> > edge1;
    std::vector<std::vector<int> > edge2;    
    std::vector<int> ent, lnt;
    std::vector<int> rec, ser;

void calc_ent(int node) {
    if (rec[node] != 0) {
        return;
    }
    for (int i = 0; i < edge1[node].size() / 2; i++) {
        int id = 2 * i;
        int t = ent[node] + edge1[node][id + 1];
        if (t > ent[edge1[node][id]]) {
            ent[edge1[node][id]] = t;
        }
        rec[edge1[node][id]]--;
        calc_ent(edge1[node][id]);
    }
    rec[node]--;
    return;
}

void calc_lnt(int node) {
    if (ser[node] != 0) {
        return;
    }
    for (int i = 0; i < edge2[node].size() / 2; i++) {
        int id = 2 * i;
        int t = lnt[node] - edge2[node][id + 1];
        if (t < lnt[edge2[node][id]]) {
            lnt[edge2[node][id]] = t;
        }
        ser[edge2[node][id]]--;
        calc_lnt(edge2[node][id]);
    }
    ser[node]--;
    return;
}

int main() {
    int tmp[3] = {0};
    int c = 0;
    std::cin >> n >> m;
    edge1.resize(n);
    edge2.resize(n);
    ent.resize(n, 0);
    ent[0] = 0;
    lnt.resize(n, std::numeric_limits<int>::max());
    rec.resize(n, 0);
    ser.resize(n, 0);
    for (int i = 0; i < m; i++) {
        std::cin >> tmp[0] >> tmp[1] >> tmp[2];
        edge1[tmp[0]].push_back(tmp[1]);
        edge1[tmp[0]].push_back(tmp[2]);
        edge2[tmp[1]].push_back(tmp[0]);
        edge2[tmp[1]].push_back(tmp[2]);
        ser[tmp[0]]++;
        rec[tmp[1]]++;
    }
    calc_ent(0);
    lnt[n-1] = ent[n-1];
    calc_lnt(n-1);
    for (int i = 0; i < n; i++) {
        if (lnt[i] != ent[i]) {
            c++;
        }
    }
    std::cout << ent[n-1] << " " << c << "/" << n << std::endl;
    
}
0