結果

問題 No.654 Air E869120
ユーザー veqccveqcc
提出日時 2019-03-13 17:29:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 263 ms / 2,000 ms
コード長 2,194 bytes
コンパイル時間 1,268 ms
コンパイル使用メモリ 121,868 KB
実行使用メモリ 175,848 KB
最終ジャッジ日時 2023-09-05 23:14:49
合計ジャッジ時間 4,478 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 9 ms
4,376 KB
testcase_11 AC 5 ms
4,384 KB
testcase_12 AC 5 ms
4,380 KB
testcase_13 AC 5 ms
4,376 KB
testcase_14 AC 5 ms
4,376 KB
testcase_15 AC 6 ms
4,376 KB
testcase_16 AC 71 ms
6,012 KB
testcase_17 AC 58 ms
5,948 KB
testcase_18 AC 45 ms
5,884 KB
testcase_19 AC 80 ms
6,000 KB
testcase_20 AC 24 ms
8,000 KB
testcase_21 AC 25 ms
8,056 KB
testcase_22 AC 14 ms
8,088 KB
testcase_23 AC 21 ms
7,996 KB
testcase_24 AC 31 ms
8,128 KB
testcase_25 AC 13 ms
8,076 KB
testcase_26 AC 16 ms
8,100 KB
testcase_27 AC 17 ms
10,624 KB
testcase_28 AC 20 ms
10,696 KB
testcase_29 AC 16 ms
10,744 KB
testcase_30 AC 263 ms
175,828 KB
testcase_31 AC 261 ms
175,848 KB
testcase_32 AC 261 ms
175,720 KB
testcase_33 AC 261 ms
175,728 KB
testcase_34 AC 261 ms
175,792 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 2 ms
4,384 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

const ll INF = 1LL << 60;

struct Edge {
    int to; ll cap; int rev;
    Edge(int t, ll c, int r) : to(t), cap(c), rev(r) {}
};

struct Flow {
    vector <vector<Edge>> G;
    vector<bool> used;
    Flow(int n) : G(n), used(n, false) {}
    void add_edge(int from, int to, ll cap) {
        G[from].push_back(Edge(to, cap, G[to].size()));
        G[to].push_back(Edge(from, 0, G[from].size() - 1));
    }
    ll dfs(int v, int t, ll f) {
        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) {
                ll 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;
    }
    ll max_flow(int s, int t) {
        ll flow = 0;
        while (1) {
            fill(used.begin(), used.end(), false);
            ll f = dfs(s, t, INF);
            if (f == 0) return flow;
            flow += f;
        }
    }
};

int main() {
    cin.sync_with_stdio(false);
    cin.tie(0);

    int n, m;
    ll d;
    cin >> n >> m >> d;

    int u[m], v[m];
    ll p[m], q[m], w[m];
    set <ll> st;
    for (int i = 0; i < m; i++) {
        cin >> u[i] >> v[i] >> p[i] >> q[i] >> w[i];
        u[i]--; v[i]--;
        st.insert(p[i]);
        st.insert(q[i] + d);
    }

    map <ll, int> mp;
    int idx = 0;
    for (auto itr = st.begin(); itr != st.end(); itr++) mp[*itr] = idx++;

    int sz = mp.size();
    Flow fl(n*sz);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < sz - 1; j++) {
            fl.add_edge(i*sz + j, i*sz + j + 1, INF);
        }
    }

    for (int i = 0; i < m; i++) {
        fl.add_edge(u[i] * sz + mp[p[i]], v[i] * sz + mp[q[i] + d], w[i]);
    }

    cout << fl.max_flow(0, n*sz - 1) << "\n";
    return 0;
}
0