結果

問題 No.654 Air E869120
ユーザー kyawashellkyawashell
提出日時 2018-06-29 16:01:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,932 bytes
コンパイル時間 1,313 ms
コンパイル使用メモリ 101,892 KB
実行使用メモリ 8,440 KB
最終ジャッジ日時 2023-09-13 15:12:11
合計ジャッジ時間 12,530 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,440 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1,879 ms
4,380 KB
testcase_11 AC 968 ms
4,376 KB
testcase_12 AC 1,103 ms
4,376 KB
testcase_13 AC 1,621 ms
4,376 KB
testcase_14 AC 778 ms
4,376 KB
testcase_15 AC 857 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<algorithm>
#include<vector>
#include<map>
#include<set>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;

#define rep(i,n) for(int i=0;i<(n);i++)
#define MAX_V (1001)

struct edge {
    P to;
    ll cap;
    ll rev_id;
};

map<P,vector<edge> > G;

set<P> used;

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

ll dfs(P v,P t,ll f) {
    if(v == t)return f;
    used.insert(v);

    rep(i,G[v].size()) {
        edge &e = G[v][i];
        if(used.find(e.to) == used.end() && e.cap > 0) {
            ll d = dfs(e.to,t,min(f,e.cap));
            if(d > 0) {
                e.cap -= d;
                G[e.to][e.rev_id].cap += d;
                return d;
            }
        }
    }
    return 0;
}

ll max_flow(P s/*始点*/,P t/*終点*/) {
    ll flow = 0;
    for(;;) {
        used.clear();
        ll f = dfs(s,t,1e18);
        if(f == 0)break;
        flow += f;
    }
    return flow;
}
ll N,M,d,u[1001],v[1001],p[1001],q[1001],w[1001];
int main() {
    cin >> N >> M >> d;
    rep(i,M) cin >> u[i] >> v[i] >> p[i] >> q[i] >> w[i]; 
    rep(i,M) {
        u[i]--;v[i]--;
        G[P(u[i],p[i])] = vector<edge>();
        G[P(v[i],q[i] + d)] = vector<edge>();
    }

    G[P(0,0)] = vector<edge>();
    G[P(N-1,2000000000)] = vector<edge>();

    rep(i,M) {
        add_edge(P(u[i],p[i]),P(v[i],q[i] + d),w[i]);
    }

    for(auto x : G) {
        P q = P(-1,-1);
        for(auto y : G) {
            if(x.first.first == y.first.first && x.first.second < y.first.second) {
                if(q == P(-1,-1) || y.first.second < q.second) {
                    q = y.first;
                }
            }
        }
        if(q != P(-1,-1)) {
            add_edge(x.first,q,1e18);
        }
    }

    cout << max_flow(P(0,0),P(N-1,2000000000)) << endl;

    return 0;
}
0