結果

問題 No.654 Air E869120
ユーザー toyontoyon
提出日時 2020-03-21 01:12:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,624 bytes
コンパイル時間 1,548 ms
コンパイル使用メモリ 171,864 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-09 11:42:44
合計ジャッジ時間 2,818 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;

typedef long long ll;
const int INF = 1e8;
// const ll INF = 1LL << 60;
typedef pair<int, int> P;

struct edge { int to, cap, rev, p, q; };
vector<edge> G[1010];
bool used[1010];

int n, m, day;

// G[e.to][e.rev] で逆辺の構造体にアクセスできる
void add_edge(int from, int to, int cap, int p, int q) {
    G[from].push_back((edge){to, cap, (int)G[to].size(), p, q});
    G[to].push_back((edge){from, 0, (int)G[from].size() - 1, p, q});
}

int dfs(int v, int t, int f, int current_time) {
    if (v == t) return f;
    used[v] = true;
    for (int i = 0; i < G[v].size(); i++) {
        edge &e = G[v][i];
        if (!used[e.to] && e.cap > 0 && e.p >= current_time) {
            int d = dfs(e.to, t, min(f, e.cap), e.q + day);
            if (d > 0) {
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}
int main_flow(int s, int t) {
    int flow = 0;
    for (;;) {
        memset(used, 0, sizeof(used));
        int f = dfs(s, t, INF, 0);
        if (f == 0) return flow;
        flow += f;
    }
}
int main() {

    cin >> n >> m >> day;
    rep(i, m) {
        int from, to, cost, p, q;
        cin >> from >> to >> p >> q >> cost;
        from--;
        to--;
        add_edge(from, to, cost, p, q);
    }
    // rep(i, n) {
    //     rep(j, G[i].size()) {
    //         cout << i << " " << j << " " << G[i][j].rev << endl;
    //     }
    // }
    cout << main_flow(0, n - 1) << endl;
}
0