結果

問題 No.654 Air E869120
ユーザー Manuel1024Manuel1024
提出日時 2021-04-06 01:26:23
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,119 bytes
コンパイル時間 1,047 ms
コンパイル使用メモリ 93,748 KB
実行使用メモリ 10,896 KB
最終ジャッジ日時 2023-08-30 13:50:36
合計ジャッジ時間 6,172 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long int;
const ll INF = 1001001001001001001;

template<class T>
class MaxFlowGraph{
private:
    struct Edge{
        int to;
        T cap;
        int rev;
    };
    using graph = vector<vector<Edge>>;
    graph G;
    vector<bool> used;

public:
    MaxFlowGraph(int n){
        G = graph(n);
        used = vector<bool>(n, false);
    }

    void add_edge(int from, int to, T cap){
        G[from].push_back({to, cap, (int)G[to].size()});
        G[to].push_back({from, 0, (int)G[from].size()-1});
    }

    T dfs(int v, int t, T f){
        if(v == t) return f;
        used[v] = true;
        for(int i = 0; i < G[v].size(); i++){
            auto &e = G[v][i];
            if(used[e.to] || e.cap == 0) continue;
            T d = dfs(e.to, t, min(f, e.cap));
            if(d > 0){
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
        return 0;
    }

    T flow(int s, int t){
        T maxflow = 0;
        while(true){
            fill(used.begin(), used.end(), false);
            T f = dfs(s, t, INF);
            if(f == 0) return maxflow;
            else maxflow += f;
        }
    }
};

int main(){
    int n, m, d;
    cin >> n >> m >> d;
    vector<int> u(m), v(m), p(m), q(m), r(m);
    for(int i = 0; i < m; i++){
        cin >> u[i] >> v[i] >> p[i] >> q[i] >> r[i];
        u[i]--;
        v[i]--;
    }

    map<int, int> memo;
    for(int i = 0; i < m; i++) memo[p[i]] = 1;
    for(int i = 0; i < m; i++) memo[q[i]+d] = 1;
    {
        int i = 0;
        for(auto &pp: memo){
            pp.second = i;
            i++;
        }
    }

    MaxFlowGraph<ll> G(n*memo.size());
    const int s = 0;
    const int t = n*memo.size()-1;
    for(int i = 0; i < m; i++){
        G.add_edge(n*memo[p[i]]+u[i], n*memo[q[i]+d]+v[i], r[i]);
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j+1 < memo.size(); j++) G.add_edge(n*j+i, n*(j+1)+i, INF);
    }

    cout << G.flow(s, t) << endl;
    return 0;
}
0