結果

問題 No.654 Air E869120
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2018-02-25 18:27:03
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 3,695 bytes
コンパイル時間 2,105 ms
コンパイル使用メモリ 186,368 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-09 21:37:12
合計ジャッジ時間 4,276 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 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 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 7 ms
4,380 KB
testcase_11 AC 6 ms
4,380 KB
testcase_12 AC 6 ms
4,376 KB
testcase_13 AC 7 ms
4,376 KB
testcase_14 AC 6 ms
4,376 KB
testcase_15 AC 6 ms
4,376 KB
testcase_16 AC 9 ms
4,380 KB
testcase_17 AC 11 ms
4,380 KB
testcase_18 AC 9 ms
4,376 KB
testcase_19 AC 9 ms
4,376 KB
testcase_20 AC 4 ms
4,376 KB
testcase_21 AC 5 ms
4,376 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 4 ms
4,380 KB
testcase_24 AC 5 ms
4,376 KB
testcase_25 AC 3 ms
4,380 KB
testcase_26 AC 4 ms
4,376 KB
testcase_27 AC 3 ms
4,376 KB
testcase_28 AC 3 ms
4,380 KB
testcase_29 AC 3 ms
4,376 KB
testcase_30 AC 3 ms
4,376 KB
testcase_31 AC 3 ms
4,376 KB
testcase_32 AC 2 ms
4,380 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 1 ms
4,376 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
template<class V> struct MaxFlow { // Dinic O(V^2E)
    struct edge { int to, reve; V cap; edge(int t, int r, V c) : to(t), reve(r), cap(c) {} };
    int MV; vector<vector<edge>> E; vector<int> itr, lev;
    MaxFlow(int n) { init(n); } MaxFlow() { }
    void init(int n){MV=n;itr=vector<int>(MV),lev = vector<int>(MV); E = vector<vector<edge>>(MV); }
    void add_edge(int x, int y, V cap, bool undir = false) {
        E[x].push_back(edge(y, (int)E[y].size(), cap));
        E[y].push_back(edge(x, (int)E[x].size() - 1, undir ? cap : 0));}
    void bfs(int cur) {rep(i, 0, MV) lev[i] = -1; queue<int> q; lev[cur] = 0; q.push(cur);
        while (q.size()) {int v = q.front(); q.pop();
        for (auto e : E[v]) if (e.cap>0 && lev[e.to]<0) lev[e.to] = lev[v] + 1, q.push(e.to);}}
    V dfs(int from,int to,V cf){if(from==to)return cf;for(; itr[from]<E[from].size(); itr[from]++) {
        edge* e = &E[from][itr[from]]; if (e->cap>0 && lev[from]<lev[e->to]) {
        V f = dfs(e->to, to, min(cf, e->cap));if(f>0){e->cap-=f;E[e->to][e->reve].cap+=f;return f; }}
        } return 0;}
    V maxflow(int from, int to) {V fl = 0, tf;while (1) {bfs(from); if (lev[to]<0) return fl;
        rep(i,0,MV)itr[i]=0; while ((tf = dfs(from, to, numeric_limits<V>::max()))>0) fl += tf;}}};
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/





int N, M, d, U[1010], V[1010], P[1010], Q[1010], W[1010];
vector<int> dic[1010];
int sz[1010];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> M >> d;
    rep(i, 0, M) {
        cin >> U[i] >> V[i] >> P[i] >> Q[i] >> W[i];
        U[i]--; V[i]--;
        Q[i] += d;
    }
    rep(i, 0, M) {
        dic[U[i]].push_back(P[i]);
        dic[V[i]].push_back(Q[i]);
    }
    rep(i, 0, N) {
        sort(all(dic[i]));
        dic[i].erase(unique(all(dic[i])), dic[i].end());
    }

    sz[0] = dic[0].size();
    rep(i, 1, N) sz[i] = sz[i - 1] + dic[i].size();

    MaxFlow<ll> mf(sz[N-1]);
    rep(i, 0, N) {
        int st = 0;
        if (i) st += sz[i - 1];
        int n = dic[i].size();
        rep(j, 0, n - 1) mf.add_edge(st + j, st + j + 1, infl);
    }
    rep(i, 0, M) {
        int a = lower_bound(all(dic[U[i]]), P[i]) - dic[U[i]].begin();
        if (U[i]) a += sz[U[i] - 1];
        int b = lower_bound(all(dic[V[i]]), Q[i]) - dic[V[i]].begin();
        if (V[i]) b += sz[V[i] - 1];
        mf.add_edge(a, b, W[i]);
    }
    
    ll ans = mf.maxflow(0, sz[N - 1] - 1);
    cout << ans << endl;
}
0