結果

問題 No.654 Air E869120
ユーザー pote-bokkopote-bokko
提出日時 2022-05-07 13:46:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,426 bytes
コンパイル時間 1,731 ms
コンパイル使用メモリ 173,172 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-20 23:19:43
合計ジャッジ時間 3,811 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1 ms
4,380 KB
testcase_02 WA -
testcase_03 AC 1 ms
4,380 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 WA -
testcase_08 AC 1 ms
4,380 KB
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 AC 3 ms
4,376 KB
testcase_30 AC 4 ms
4,376 KB
testcase_31 AC 4 ms
4,380 KB
testcase_32 AC 3 ms
4,380 KB
testcase_33 AC 3 ms
4,380 KB
testcase_34 AC 4 ms
4,380 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 1 ms
4,376 KB
testcase_39 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define ll long long
#define MOD 1000000007
#define MOD2 998244353
#define INF 1e9

struct edge{
    ll to, cap, rev, p, q;
};

vector<vector<edge>> G;
vector<ll> used;
ll n, m;

void add_edge(ll u, ll v, ll c, ll p, ll q){
    G[u].push_back((edge){v, c, (ll)G[v].size(), p, q});
    G[v].push_back((edge){u, 0, (ll)G[u].size()-1, (ll)INF, p});
}

ll dfs(ll v, ll t, ll f, int time){
    if(time > 1e9)return 0;
    if(v == t)return f;
    used[v] = 1;
    rep(i, G[v].size()){
        edge &e = G[v][i];
        if(time > G[v][i].p) continue;
        if(e.cap > 0 && !used[e.to]){
            ll d = dfs(e.to, t, min(f, e.cap), G[v][i].q);
            if(d > 0){
                G[v][i].cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

ll max_flow(ll s, ll t){
    ll flow = 0;
    for(;;){
        for(ll i=0; i<n; i++)used[i] = 0;
        ll f = dfs(s, t, INF, 0);
        if(f == 0)return flow;
        flow += f;
    }
}

int main(void){
    ll d;
    cin >> n >> m >> d;
    G.resize(n);
    used.resize(n);
    rep(i, m){
        ll u, v, p, q, w;
        cin >> u >> v >> p >> q >> w;
        u--, v--;
        if(u != 0)add_edge(u, v, w, p-d, q);
        else add_edge(u, v, w, p, q);
    }
    cout << max_flow(0, n-1) << endl;
    return 0;
}
0