結果

問題 No.468 役に立つ競技プログラミング実践編
ユーザー mamekinmamekin
提出日時 2017-06-11 15:07:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 332 ms / 2,000 ms
コード長 2,010 bytes
コンパイル時間 1,125 ms
コンパイル使用メモリ 113,456 KB
実行使用メモリ 18,936 KB
最終ジャッジ日時 2023-10-24 21:02:53
合計ジャッジ時間 7,662 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 3 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 4 ms
4,348 KB
testcase_15 AC 5 ms
4,348 KB
testcase_16 AC 4 ms
4,348 KB
testcase_17 AC 4 ms
4,348 KB
testcase_18 AC 4 ms
4,348 KB
testcase_19 AC 4 ms
4,348 KB
testcase_20 AC 5 ms
4,348 KB
testcase_21 AC 4 ms
4,348 KB
testcase_22 AC 4 ms
4,348 KB
testcase_23 AC 4 ms
4,348 KB
testcase_24 AC 325 ms
18,936 KB
testcase_25 AC 332 ms
18,936 KB
testcase_26 AC 330 ms
18,936 KB
testcase_27 AC 332 ms
18,936 KB
testcase_28 AC 332 ms
18,936 KB
testcase_29 AC 328 ms
18,936 KB
testcase_30 AC 330 ms
18,936 KB
testcase_31 AC 330 ms
18,936 KB
testcase_32 AC 329 ms
18,936 KB
testcase_33 AC 325 ms
18,936 KB
testcase_34 AC 98 ms
15,768 KB
testcase_35 AC 3 ms
4,348 KB
testcase_36 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

class Edge
{
public:
    int to, cost;
    Edge(int to, int cost){
        this->to = to;
        this->cost = cost;
    }
};

int main()
{
    int n, m;
    cin >> n >> m;
    vector<vector<Edge> > edges(n);
    vector<vector<Edge> > revEdges(n);
    vector<int> out(n, 0);
    vector<int> in(n, 0);
    for(int i=0; i<m; ++i){
        int a, b, c;
        cin >> a >> b >> c;
        edges[a].push_back(Edge(b, c));
        revEdges[b].push_back(Edge(a, c));
        ++ out[a];
        ++ in[b];
    }

    queue<int> q;
    vector<int> fast(n, 0);
    for(int i=0; i<n; ++i){
        if(in[i] == 0)
            q.push(i);
    }
    while(!q.empty()){
        int curr = q.front();
        q.pop();
        for(const Edge& e : edges[curr]){
            fast[e.to] = max(fast[e.to], fast[curr] + e.cost);
            -- in[e.to];
            if(in[e.to] == 0)
                q.push(e.to);
        }
    }

    vector<int> slow(n, INT_MAX);
    for(int i=0; i<n; ++i){
        if(out[i] == 0){
            slow[i] = fast[i];
            q.push(i);
        }
    }
    while(!q.empty()){
        int curr = q.front();
        q.pop();
        for(const Edge& e : revEdges[curr]){
            slow[e.to] = min(slow[e.to], slow[curr] - e.cost);
            -- out[e.to];
            if(out[e.to] == 0)
                q.push(e.to);
        }
    }

    int ans = 0;
    for(int i=0; i<n; ++i){
        if(fast[i] < slow[i])
            ++ ans;
    }
    cout << *max_element(fast.begin(), fast.end()) << ' '
         << ans << '/' << n << endl;

    return 0;
}
0