結果

問題 No.654 Air E869120
ユーザー 303Yuyu303Yuyu
提出日時 2021-02-12 21:45:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 3,384 bytes
コンパイル時間 2,078 ms
コンパイル使用メモリ 180,824 KB
実行使用メモリ 6,152 KB
最終ジャッジ日時 2023-09-27 03:31:52
合計ジャッジ時間 4,014 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 12 ms
6,152 KB
testcase_11 AC 11 ms
5,428 KB
testcase_12 AC 11 ms
5,772 KB
testcase_13 AC 11 ms
5,816 KB
testcase_14 AC 10 ms
5,304 KB
testcase_15 AC 11 ms
5,900 KB
testcase_16 AC 6 ms
4,592 KB
testcase_17 AC 6 ms
4,716 KB
testcase_18 AC 6 ms
4,680 KB
testcase_19 AC 6 ms
4,488 KB
testcase_20 AC 5 ms
4,380 KB
testcase_21 AC 5 ms
4,376 KB
testcase_22 AC 4 ms
4,380 KB
testcase_23 AC 5 ms
4,380 KB
testcase_24 AC 5 ms
4,380 KB
testcase_25 AC 5 ms
4,376 KB
testcase_26 AC 5 ms
4,376 KB
testcase_27 AC 4 ms
4,380 KB
testcase_28 AC 4 ms
4,376 KB
testcase_29 AC 4 ms
4,376 KB
testcase_30 AC 3 ms
4,376 KB
testcase_31 AC 3 ms
4,380 KB
testcase_32 AC 3 ms
4,380 KB
testcase_33 AC 3 ms
4,376 KB
testcase_34 AC 3 ms
4,376 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#include <atcoder/all>

using namespace std;
//using namespace atcoder;

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using ld = long double;
using vld = vector<ld>;
using vb = vector<bool>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define dbg(x) true
#endif

template <class T> bool chmin(T& a, T b) {
    if(a > b) { a = b; return true; }
    else return false;
}

template <class T> bool chmax(T& a, T b) {
    if(a < b) { a = b; return true; }
    else return false;
}

template <class T> ostream& operator<<(ostream& s, const vector<T>& a) {
    for(auto i : a) s << i << ' ';
    return s;
}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

struct Edge {
    ll to, cap, rev;
    Edge(ll to, ll cap, ll rev) : to(to), cap(cap), rev(rev) {};
};

struct Dinic {
    ll n;
    vector<vector<Edge>> g;
    vector<ll> level, iter;
    Dinic(ll n) : n(n), g(n), iter(n) {};

    void add_edge(ll from, ll to, ll cap) {
        g[from].emplace_back(to, cap, (ll)g[to].size());
        g[to].emplace_back(from, 0, (ll)g[from].size()-1);
    }

    // 容量が残っているパスにおける始点からの距離を計算
    void bfs(ll s) {
        level.assign(n, -1);
        queue<ll> que;
        level[s] = 0;
        que.push(s);
        while(!que.empty()) {
            ll v = que.front();
            que.pop();
            for(ll i = 0; i < (ll)g[v].size(); ++i) {
                Edge& e = g[v][i];
                if(e.cap > 0 && level[e.to] < 0) {
                    level[e.to] = level[v] + 1;
                    que.push(e.to);
                }
            }
        }
    }

    // levelが増えるパスにおけるflowを計算
    ll dfs(ll v, ll t, ll f) {
        if(v == t) return f;
        // iter[v]を増やすことで各Edgeの探査は1回のみとする
        for(ll& i = iter[v]; i < (ll)g[v].size(); ++i) {
            Edge& e = g[v][i];
            if(e.cap > 0 && level[v] < level[e.to]) {
                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(ll s, ll t) {
        ll flow = 0;
        while(true) {
            bfs(s);
            if(level[t] < 0) return flow;
            iter.assign(n, 0);
            ll f;
            while((f = dfs(s, t, INFL)) > 0) { flow += f; }
        }
    }
};

void solve() {
    ll n, m, d;
    cin >> n >> m >> d;
    vll u(m), v(m), p(m), q(m), w(m);
    rep(i, m) cin >> u[i] >> v[i] >> p[i] >> q[i] >> w[i];

    Dinic D(2*m+2);
    rep(i, m) {
        D.add_edge(i, i+m, w[i]);
        if(u[i] == 1) D.add_edge(2*m, i, w[i]);
        if(v[i] == n) D.add_edge(i+m, 2*m+1, w[i]);
    }
    rep(fr, m) rep(to, m) {
        if(v[fr] == u[to] && q[fr] + d <= p[to]) {
            D.add_edge(fr+m, to, max(w[fr], w[to]));
        }
    }
    cout << D.max_flow(2*m, 2*m+1) << endl;
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}
0