結果

問題 No.468 役に立つ競技プログラミング実践編
ユーザー nebukuro09
提出日時 2016-12-18 15:27:17
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 280 ms / 2,000 ms
コード長 1,223 bytes
コンパイル時間 1,728 ms
コンパイル使用メモリ 155,600 KB
実行使用メモリ 31,360 KB
最終ジャッジ日時 2024-06-12 05:41:00
合計ジャッジ時間 7,050 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 31
other AC * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;


alias Tuple!(int, "e", int, "c") edge;
int N, M, a, b, c;
int[] earliest, latest;
edge[][] adj;
edge[][] inv;

int rec_back(int n) {
    if (earliest[n] > -1)
        return earliest[n];
    earliest[n] = inv[n].map!(to => rec_back(to.e)+to.c).reduce!(max);
    return earliest[n];
}

int rec_forward(int n) {
    if (latest[n] > -1)
        return latest[n];
    latest[n] = adj[n].map!(to => rec_forward(to.e)-to.c).reduce!(min);
    return latest[n];
}

void main() {
    scanf("%d %d", &N, &M);

    adj = new edge[][](N);
    inv = new edge[][](N);
    foreach (i; 0..M) {
        scanf("%d %d %d", &a, &b, &c);
        adj[a] ~= edge(b, c);
        inv[b] ~= edge(a, c);
    }

    earliest = new int[](N);
    earliest[0] = 0;
    foreach (i; 1..N) earliest[i] = -1;
    rec_back(N-1);

    latest = new int[](N);
    latest[N-1] = earliest[N-1];
    foreach (i; 0..N-1) latest[i] = -1;
    rec_forward(0);

    int ans = N.iota.map!(n => earliest[n] < latest[n]).sum;
    writefln("%d %d/%d", latest[N-1], ans, N);
}
0