結果

問題 No.468 役に立つ競技プログラミング実践編
ユーザー imulanimulan
提出日時 2016-12-18 00:58:21
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 149 ms / 2,000 ms
コード長 1,512 bytes
コンパイル時間 1,457 ms
コンパイル使用メモリ 169,616 KB
実行使用メモリ 20,488 KB
最終ジャッジ日時 2023-08-21 00:19:28
合計ジャッジ時間 4,700 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
9,440 KB
testcase_01 AC 4 ms
9,400 KB
testcase_02 AC 4 ms
9,432 KB
testcase_03 AC 5 ms
9,464 KB
testcase_04 AC 4 ms
9,324 KB
testcase_05 AC 4 ms
9,432 KB
testcase_06 AC 4 ms
9,340 KB
testcase_07 AC 4 ms
9,404 KB
testcase_08 AC 4 ms
9,396 KB
testcase_09 AC 4 ms
9,408 KB
testcase_10 AC 4 ms
9,328 KB
testcase_11 AC 4 ms
9,404 KB
testcase_12 AC 4 ms
9,444 KB
testcase_13 AC 4 ms
9,372 KB
testcase_14 AC 5 ms
9,680 KB
testcase_15 AC 6 ms
9,496 KB
testcase_16 AC 5 ms
9,564 KB
testcase_17 AC 5 ms
9,468 KB
testcase_18 AC 5 ms
9,500 KB
testcase_19 AC 5 ms
9,424 KB
testcase_20 AC 5 ms
9,484 KB
testcase_21 AC 6 ms
9,524 KB
testcase_22 AC 5 ms
9,428 KB
testcase_23 AC 5 ms
9,560 KB
testcase_24 AC 146 ms
19,192 KB
testcase_25 AC 147 ms
19,308 KB
testcase_26 AC 147 ms
19,484 KB
testcase_27 AC 146 ms
19,296 KB
testcase_28 AC 145 ms
19,244 KB
testcase_29 AC 146 ms
19,264 KB
testcase_30 AC 144 ms
19,276 KB
testcase_31 AC 149 ms
19,272 KB
testcase_32 AC 146 ms
19,320 KB
testcase_33 AC 145 ms
19,196 KB
testcase_34 AC 51 ms
20,488 KB
testcase_35 AC 5 ms
9,436 KB
testcase_36 AC 4 ms
9,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

typedef pair<int,int> pi;

const int N=100000;
const int INF=1010101010;

struct edge{ int to,cost; };

int n,m;

vector<edge> G[N],rG[N];
int d[N],rd[N];

int vis[N];
vector<int> vlist;

void dfs(int v)
{
    if(vis[v]) return;

    vis[v]=1;
    rep(i,G[v].size())
    {
        edge e=G[v][i];
        dfs(e.to);
    }
    vlist.pb(v);
}

void tsort()
{
    fill(vis,vis+N,0);
    rep(i,n) dfs(i);
}


int main()
{
    scanf(" %d %d", &n, &m);
    rep(i,m)
    {
        int a,b,c;
        scanf(" %d %d %d", &a, &b, &c);
        G[a].pb(edge{b,c});
        rG[b].pb(edge{a,c});
    }

    tsort();
    int V=vlist.size();

    fill(d,d+N,0);
    for(int i=V-1; i>=0; --i)
    {
        int v=vlist[i];
        rep(j,G[v].size())
        {
            edge e=G[v][j];
            d[e.to]=max(d[e.to], d[v]+e.cost);
        }
    }

    fill(rd,rd+N,0);
    rep(i,V)
    {
        int v=vlist[i];
        rep(j,rG[v].size())
        {
            edge e=rG[v][j];
            rd[e.to]=max(rd[e.to], rd[v]+e.cost);
        }

    }

    // rep(i,n) printf("%d: d = %d, rd = %d\n", i,d[i],d[n-1]-rd[i]);

    int ct=0;
    rep(i,n) ct+=(d[i]==d[n-1]-rd[i]);

    printf("%d %d/%d\n", d[n-1], n-ct, n);
    return 0;
}
0