結果

問題 No.654 Air E869120
ユーザー kyawashellkyawashell
提出日時 2018-06-29 15:55:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,945 bytes
コンパイル時間 1,052 ms
コンパイル使用メモリ 101,852 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-13 15:11:10
合計ジャッジ時間 12,511 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1,869 ms
4,376 KB
testcase_11 AC 959 ms
4,376 KB
testcase_12 AC 1,091 ms
4,376 KB
testcase_13 AC 1,602 ms
4,376 KB
testcase_14 AC 760 ms
4,376 KB
testcase_15 AC 847 ms
4,380 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 143 ms
4,380 KB
testcase_30 AC 150 ms
4,376 KB
testcase_31 AC 152 ms
4,376 KB
testcase_32 AC 152 ms
4,376 KB
testcase_33 AC 148 ms
4,376 KB
testcase_34 AC 150 ms
4,376 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;

#define rep(i,n) for(int i=0;i<(n);i++)
#define MAX_V (1001)

struct edge {
    P to;
    ll cap;
    ll rev_id;
};

map<P,vector<edge> > G;

set<P> used;

void add_edge(P from,P to,ll cap) {
    G[from].push_back((edge){to,cap,(ll)G[to].size()});
    G[to].push_back((edge){from,0,(ll)G[from].size() - 1});
}

ll dfs(P v,P t,ll f) {
    if(v == t)return f;
    used.insert(v);

    rep(i,G[v].size()) {
        edge &e = G[v][i];
        if(used.find(e.to) == used.end() && e.cap > 0) {
            ll d = dfs(e.to,t,min(f,e.cap));
            if(d > 0) {
                e.cap -= d;
                G[e.to][e.rev_id].cap += d;
                return d;
            }
        }
    }
    return 0;
}

ll max_flow(P s/*始点*/,P t/*終点*/) {
    ll flow = 0;
    for(;;) {
        used.clear();
        ll f = dfs(s,t,10000000000);
        if(f == 0)break;
        flow += f;
    }
    return flow;
}
ll N,M,d,u[1001],v[1001],p[1001],q[1001],w[1001];
int main() {
    cin >> N >> M >> d;
    rep(i,M) cin >> u[i] >> v[i] >> p[i] >> q[i] >> w[i]; 
    rep(i,M) {
        u[i]--;v[i]--;
        G[P(u[i],p[i])] = vector<edge>();
        G[P(v[i],q[i] + d)] = vector<edge>();
    }

    G[P(0,0)] = vector<edge>();
    G[P(N-1,1000000000)] = vector<edge>();

    rep(i,M) {
        add_edge(P(u[i],p[i]),P(v[i],q[i] + d),w[i]);
    }

    for(auto x : G) {
        P q = P(-1,-1);
        for(auto y : G) {
            if(x.first.first == y.first.first && x.first.second < y.first.second) {
                if(q == P(-1,-1) || y.first.second < q.second) {
                    q = y.first;
                }
            }
        }
        if(q != P(-1,-1)) {
            add_edge(x.first,q,1000000000);
        }
    }

    cout << max_flow(P(0,0),P(N-1,1000000000)) << endl;

    return 0;
}
0