結果

問題 No.654 Air E869120
ユーザー 303Yuyu303Yuyu
提出日時 2021-02-12 21:47:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 121 ms / 2,000 ms
コード長 2,860 bytes
コンパイル時間 1,837 ms
コンパイル使用メモリ 178,464 KB
実行使用メモリ 6,144 KB
最終ジャッジ日時 2023-09-27 03:35:22
合計ジャッジ時間 3,911 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 121 ms
6,144 KB
testcase_11 AC 49 ms
5,084 KB
testcase_12 AC 90 ms
5,412 KB
testcase_13 AC 91 ms
5,492 KB
testcase_14 AC 27 ms
5,140 KB
testcase_15 AC 41 ms
5,936 KB
testcase_16 AC 9 ms
4,468 KB
testcase_17 AC 12 ms
4,668 KB
testcase_18 AC 9 ms
4,504 KB
testcase_19 AC 13 ms
4,548 KB
testcase_20 AC 5 ms
4,376 KB
testcase_21 AC 5 ms
4,380 KB
testcase_22 AC 4 ms
4,380 KB
testcase_23 AC 4 ms
4,376 KB
testcase_24 AC 5 ms
4,376 KB
testcase_25 AC 4 ms
4,376 KB
testcase_26 AC 4 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,376 KB
testcase_32 AC 3 ms
4,376 KB
testcase_33 AC 3 ms
4,380 KB
testcase_34 AC 3 ms
4,376 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 1 ms
4,376 KB
testcase_39 AC 2 ms
4,380 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 FordFulkerson {
    ll n;
    vector<vector<Edge>> g;
    vector<bool> used;
    FordFulkerson(ll n) : n(n), g(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);
    }

    ll dfs(ll v, ll t, ll f) {
        if(v == t) return f;    // 終点に到達した時のminのflow
        used[v] = true;
        for(ll i = 0; i < (ll)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)); // 先に進むごとにe.capとのminに減らす
                if(d > 0) {
                    e.cap -= d;
                    g[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;   // 終点に到達しなければflowの増量は0
    }

    ll max_flow(ll s, ll t) {
        ll flow = 0;
        while(true) {
            used.assign(n, false);
            ll f = dfs(s, t, INFL); // 終点に到達した時のminのflow
            if(f == 0) return flow;
            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];

    FordFulkerson 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