結果

問題 No.468 役に立つ競技プログラミング実践編
ユーザー cormorancormoran
提出日時 2016-12-20 17:41:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,953 bytes
コンパイル時間 2,624 ms
コンパイル使用メモリ 177,812 KB
実行使用メモリ 19,576 KB
最終ジャッジ日時 2023-08-21 03:18:33
合計ジャッジ時間 6,430 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 51 ms
19,576 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;


class Solver {
  public:
    int N, M;
    vector<vector<pii>> E;
    vector<vector<pii>> RE;

    vector<int> earliest, latest;
    
    int calc_earliest(int now) {
        if(earliest[now] >= 0) return earliest[now];
        int res = 0;
        for(auto e : RE[now]) {                
            set_max(res, calc_earliest(e.first) + e.second);
        }
        return earliest[now] = res;
    }

    int calc_latest(int now) {
        if(latest[now] < INF) return latest[now];
        int res = earliest[N - 1];
        for(auto e: E[now]) {
            set_min(res, calc_latest(e.first) - e.second);
        }
        return latest[now] = res;
    }
    
    vector<int> calc_critical_path(const vector<int> &earliest, const vector<int> &latest) {
        vector<int> ret;
        int now = N - 1;
        while(now != 0) {
            ret.push_back(now);
            int nxt = -1;
            for(auto e : RE[now]) {
                if(earliest[e.first] == latest[e.first]) {
                    nxt = e.first;
                    break;
                }
            }
            assert(nxt >= 0);
            now = nxt;
        }
        ret.push_back(now);
        return ret;
    }
    
    bool solve() {
        cin >> N >> M;
        E.resize(N);
        RE.resize(N);
        
        rep(i, M) {
            int a, b, c; cin >> a >> b >> c;
            E[a].push_back(make_pair(b, c));
            RE[b].push_back(make_pair(a, c));
        }
        
        earliest.resize(N, -1);
        latest.resize(N, INF);

        calc_earliest(N - 1);
        calc_latest(0);
        
        //cerr << earliest << endl;
        //cerr << latest << endl;
        //cerr << calc_critical_path(earliest, latest) << endl;

        int T = earliest[N - 1];
        int P = N - calc_critical_path(earliest, latest).size();

        cout << T << " " << P << "/" << N << endl;
        
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}
0