結果

問題 No.468 役に立つ競技プログラミング実践編
ユーザー parukiparuki
提出日時 2016-12-18 00:29:09
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 269 ms / 2,000 ms
コード長 1,905 bytes
コンパイル時間 2,694 ms
コンパイル使用メモリ 176,544 KB
実行使用メモリ 27,420 KB
最終ジャッジ日時 2023-08-20 22:09:26
合計ジャッジ時間 6,215 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 4 ms
4,376 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 3 ms
4,376 KB
testcase_22 AC 4 ms
4,380 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 252 ms
27,164 KB
testcase_25 AC 243 ms
27,188 KB
testcase_26 AC 242 ms
27,208 KB
testcase_27 AC 250 ms
27,176 KB
testcase_28 AC 237 ms
27,420 KB
testcase_29 AC 269 ms
27,312 KB
testcase_30 AC 247 ms
27,136 KB
testcase_31 AC 239 ms
27,308 KB
testcase_32 AC 242 ms
27,164 KB
testcase_33 AC 247 ms
27,240 KB
testcase_34 AC 77 ms
25,876 KB
testcase_35 AC 3 ms
4,376 KB
testcase_36 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

vector<int> topologicalSort(const vector<vector<int> > &graph) {
    int V = (int)graph.size(), cur = 0;
    vector<int> deg(V), res(V);
    stack<int> stk;
    for(int i = 0; i < V; ++i)
        for(int v : graph[i])deg[v]++;
    for(int i = 0; i < V; ++i)if(deg[i] == 0)stk.push(i);
    while(!stk.empty()) {
        int v = stk.top(); stk.pop();
        res[cur++] = v;
        for(int w : graph[v])if(!--deg[w])stk.push(w);
    }
    return cur == V ? res : vector<int>();
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, M;
    cin >> N >> M;
    vector<vi> G(N), W(N), X(N), H(N);
    rep(i, M) {
        int u, v, c;
        cin >> u >> v >> c;
        G[u].push_back(v);
        W[u].push_back(c);
        H[v].push_back(u);
        X[v].push_back(c);
    }

    auto vs = topologicalSort(G);
    vi dp(N);
    each(u, vs) {
        rep(i, sz(G[u])) {
            int v = G[u][i], c = W[u][i];
            smax(dp[v], dp[u] + c);
        }
    }
    
    queue<int> q;
    q.push(N - 1);
    vi vis(N);
    while(sz(q)) {
        int u = q.front(); q.pop();
        if(vis[u])continue;
        vis[u] = 1;
        rep(i, sz(H[u])) {
            int v, c;
            v = H[u][i], c = X[u][i];
            if(dp[v] + c == dp[u] && !vis[v])q.push(v);
        }
    }

    cout << dp[N - 1] << ' ' << count(all(vis), 0) << '/' << N << endl;
}
0