結果

問題 No.654 Air E869120
ユーザー NAMIDAIRONAMIDAIRO
提出日時 2024-04-24 01:15:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,099 bytes
コンパイル時間 1,595 ms
コンパイル使用メモリ 113,880 KB
実行使用メモリ 27,240 KB
最終ジャッジ日時 2024-04-24 01:15:25
合計ジャッジ時間 3,165 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 9 ms
5,376 KB
testcase_11 AC 6 ms
5,376 KB
testcase_12 AC 6 ms
5,376 KB
testcase_13 AC 6 ms
5,376 KB
testcase_14 AC 6 ms
5,376 KB
testcase_15 AC 6 ms
5,376 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 5 ms
5,376 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 5 ms
5,376 KB
testcase_26 WA -
testcase_27 AC 5 ms
5,376 KB
testcase_28 WA -
testcase_29 AC 5 ms
5,376 KB
testcase_30 AC 13 ms
27,064 KB
testcase_31 AC 14 ms
27,200 KB
testcase_32 AC 15 ms
27,032 KB
testcase_33 AC 13 ms
27,220 KB
testcase_34 AC 15 ms
27,240 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 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)

template<class T>
using vi = vector<T>;

template<class T>
using vii = vector<vi<T>>;

template<class T>
using viii = vector<vii<T>>;

struct FF {
    struct edge {
        int to, rev; ll cap;
    };

    int n;
    vii<edge> to;
    vi<bool> visited;

    FF(int n_ = 1) : n(n_), to(n_){}

    void addedge(int u, int v, ll c) {
        int su = (int)to[u].size();
        int sv = (int)to[v].size();

        to[u].push_back({ v, sv, c });
        to[v].push_back({ u, su, 0 });
    }

    ll dfs(int v, int t, ll f = 1e18) {
        if (v == t) return f;
        visited[v] = true;
        for (edge& nv : to[v]) {
            if (visited[nv.to] || nv.cap == 0) continue;
            ll nf = dfs(nv.to, t, min(f, nv.cap));
            if (nf > 0) {
                nv.cap -= nf;
                to[nv.to][nv.rev].cap += nf;
                return nf;
            }
        }
        return 0; //忘れがち
    }

    ll maxflow(int s, int t) {
        ll res = 0, flow = 0;
        do {
            visited.assign(n, false);
            flow = dfs(s, t);
            res += flow;
        } while (flow);
        return res;
    }
};

int main()
{
    int n, m, d;
    cin >> n >> m >> d;
    vi<int> u(m), v(m), p(m), q(m); vi<ll> w(m);
    rep(i, m) cin >> u[i] >> v[i] >> p[i] >> q[i] >> w[i];
    rep(i, m) u[i]--, v[i]--;
    rep(i, m) q[i] += d;
    vi<map<int, int>> mp(n);
    rep(i, m) {
        mp[u[i]][p[i]];
        mp[v[i]][q[i]];
    }

    const int inf = 2e9;
    FF ff(n * m);
    int idx = 0;
    rep(i, n) {
        bool ng = true;
        for (auto& elem : mp[i]) {
            elem.second = idx;
            if (ng) ng = false;
            else ff.addedge(idx - 1, idx, inf);
            idx++;
        }
    }

    rep(i, m) ff.addedge(mp[u[i]][p[i]], mp[v[i]][q[i]], w[i]);

    ll res = ff.maxflow(0, idx - 1);
    cout << res << endl;

    return 0;
}
0