結果

問題 No.468 役に立つ競技プログラミング実践編
ユーザー kimiyukikimiyuki
提出日時 2016-12-20 02:16:45
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 303 ms / 2,000 ms
コード長 1,744 bytes
コンパイル時間 1,116 ms
コンパイル使用メモリ 86,044 KB
実行使用メモリ 18,240 KB
最終ジャッジ日時 2023-08-21 03:00:54
合計ジャッジ時間 6,839 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 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,388 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,384 KB
testcase_14 AC 4 ms
4,384 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 4 ms
4,380 KB
testcase_17 AC 4 ms
4,384 KB
testcase_18 AC 4 ms
4,384 KB
testcase_19 AC 4 ms
4,384 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 AC 3 ms
4,380 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 300 ms
17,984 KB
testcase_25 AC 303 ms
18,116 KB
testcase_26 AC 299 ms
18,240 KB
testcase_27 AC 299 ms
18,032 KB
testcase_28 AC 298 ms
18,216 KB
testcase_29 AC 301 ms
18,040 KB
testcase_30 AC 297 ms
18,100 KB
testcase_31 AC 303 ms
18,164 KB
testcase_32 AC 299 ms
18,012 KB
testcase_33 AC 294 ms
18,020 KB
testcase_34 AC 94 ms
15,124 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 2 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <queue>
#include <tuple>
#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))
using namespace std;
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
template <class T> void setmax(T & a, T const & b) { if (a < b) a = b; }
template <class T> void setmin(T & a, T const & b) { if (b < a) a = b; }
int main() {
    int n, m; cin >> n >> m;
    vector<vector<pair<int, int> > > g(n);
    vector<vector<pair<int, int> > > h(n);
    repeat (i,m) {
        int a, b, c; cin >> a >> b >> c;
        g[a].emplace_back(b, c);
        h[b].emplace_back(a, c);
    }
    vector<int> fast(n); {
        reversed_priority_queue<pair<int, int> > que;
        vector<int> done(n);
        que.emplace(0, 0);
        while (not que.empty()) {
            int a = que.top().second; que.pop();
            for (auto it : g[a]) {
                int b, c; tie(b, c) = it;
                setmax(fast[b], fast[a] + c);
                done[b] += 1;
                if (done[b] == h[b].size()) que.emplace(fast[b], b);
            }
        }
    }
    vector<int> slow(n, fast[n-1]); {
        priority_queue<pair<int, int> > que;
        vector<int> done(n);
        que.emplace(fast[n-1], n-1);
        while (not que.empty()) {
            int b = que.top().second; que.pop();
            for (auto it : h[b]) {
                int a, c; tie(a, c) = it;
                setmin(slow[a], slow[b] - c);
                done[a] += 1;
                if (done[a] == g[a].size()) que.emplace(slow[a], a);
            }
        }
    }
    int t = fast[n-1];
    int p = 0; repeat (a,n) p += fast[a] < slow[a];
    cout << t << ' ' << p << '/' << n << endl;
    return 0;
}
0