結果

問題 No.468 役に立つ競技プログラミング実践編
ユーザー firiexpfiriexp
提出日時 2019-12-27 21:23:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 148 ms / 2,000 ms
コード長 1,549 bytes
コンパイル時間 1,086 ms
コンパイル使用メモリ 105,468 KB
実行使用メモリ 19,072 KB
最終ジャッジ日時 2024-04-27 15:47:22
合計ジャッジ時間 4,650 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 3 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 147 ms
19,016 KB
testcase_25 AC 137 ms
19,072 KB
testcase_26 AC 145 ms
18,944 KB
testcase_27 AC 140 ms
19,072 KB
testcase_28 AC 146 ms
19,072 KB
testcase_29 AC 138 ms
18,904 KB
testcase_30 AC 148 ms
19,072 KB
testcase_31 AC 142 ms
18,944 KB
testcase_32 AC 144 ms
18,944 KB
testcase_33 AC 142 ms
19,056 KB
testcase_34 AC 43 ms
16,000 KB
testcase_35 AC 2 ms
5,376 KB
testcase_36 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <limits>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<pair<int, int>>> G(n), Ginv(n);
    vector<int> d(n), d2(n);
    for (int i = 0; i < m; ++i) {
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);
        G[a].emplace_back(b, c);
        Ginv[b].emplace_back(a, c);
        d[b]++;
        d2[a]++;
    }
    vector<int> dp(n);
    stack<int> S;
    for (int i = 0; i < n; ++i) if(!d[i]) S.emplace(i);
    while(!S.empty()){
        int i = S.top(); S.pop();
        for (auto &&j : G[i]) {
            dp[j.first] = max(dp[j.first], dp[i]+j.second);
            d[j.first]--;
            if(!d[j.first]) S.emplace(j.first);
        }
    }
    vector<int> dp2(n, INF<int>);
    dp2.back() = dp.back();
    S.emplace(n-1);
    while(!S.empty()){
        int i = S.top(); S.pop();
        for (auto &&j : Ginv[i]) {
            dp2[j.first] = min(dp2[j.first], dp2[i]-j.second);
            d2[j.first]--;
            if(!d2[j.first]) S.emplace(j.first);
        }
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        if(dp[i] != dp2[i]) ans++;
    }
    printf("%d %d/%d\n", dp.back(), ans, n);
    return 0;
}
0