結果
問題 | No.654 Air E869120 |
ユーザー | ptolomaeus |
提出日時 | 2020-01-18 16:35:30 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,370 bytes |
コンパイル時間 | 1,500 ms |
コンパイル使用メモリ | 127,968 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-27 16:19:26 |
合計ジャッジ時間 | 2,998 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
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 | 13 ms
6,656 KB |
testcase_11 | AC | 11 ms
5,760 KB |
testcase_12 | AC | 10 ms
6,144 KB |
testcase_13 | AC | 11 ms
6,016 KB |
testcase_14 | AC | 10 ms
5,504 KB |
testcase_15 | AC | 11 ms
6,400 KB |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | AC | 8 ms
5,376 KB |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | AC | 7 ms
5,376 KB |
testcase_26 | WA | - |
testcase_27 | AC | 7 ms
5,376 KB |
testcase_28 | WA | - |
testcase_29 | AC | 7 ms
5,376 KB |
testcase_30 | AC | 7 ms
5,376 KB |
testcase_31 | AC | 7 ms
5,376 KB |
testcase_32 | AC | 7 ms
5,376 KB |
testcase_33 | AC | 6 ms
5,376 KB |
testcase_34 | AC | 6 ms
5,376 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 |
ソースコード
#include <stdio.h> #include <algorithm> #include <utility> #include <functional> #include <cstring> #include <queue> #include <stack> #include <cmath> #include <iterator> #include <vector> #include <string> #include <set> #include <iostream> #include <random> #include <map> #include <iomanip> #include <stdlib.h> #include <list> #include <typeinfo> #include <list> #include <set> #include <cassert> #include <fstream> #include <unordered_map> #include <cstdlib> #include <complex> #include <cctype> #include <bitset> using namespace std; using ll = long long; using vll = vector<ll>; using pll = pair<ll, ll>; using qll = queue<ll>; using vb = vector<bool>; using mll = map<ll, ll>; using sll = stack<ll>; #define REP(i,n) for(ll i(0);(i)<(n);(i)++) #define rep(i,n) for(ll i(0);(i)<(n);(i)++) #define ALL(a) a.begin(), a.end() #define elnd endl //* missspell check const ll INF = 1LL << 60; struct edgeForFlow{ll to, cap, rev; }; //! cap: may change; rev: pointer in G[to] void addEdgeForFlow(vector<vector<edgeForFlow>> &G, ll from, ll to, ll cap){ G[from].push_back((edgeForFlow){ to, cap, (ll) G[to].size()}); G[to].push_back((edgeForFlow) { from, 0, (ll) G[from].size()-1}); } int dfsFordFulkson(vector<vector<edgeForFlow>> &G, vb &checked, ll v, ll t, ll f){ //* v: current vertex, t: sink, f: DELTA of this path. (No need for source) if(v == t) return f; checked[v] = true; REP(i, G[v].size()){ edgeForFlow &e = G[v][i]; if(!checked[e.to] && e.cap > 0){ ll d = dfsFordFulkson(G, checked, e.to, t, min(f, e.cap)); if(d > 0){ e.cap -= d; G[e.to][e.rev].cap += d; return d; } } } return 0; //* if no valid outgoing edges } int maxFlowFordFulkson(vector<vector<edgeForFlow>> &G, ll s, ll t){ vb checked(G.size()); ll flow = 0; for(;;){ fill(ALL(checked), false); ll f = dfsFordFulkson(G, checked, s, t, INF); if(f == 0) return flow; flow += f; } } void bfsDinic(vector<vector<edgeForFlow>> &G, vll &level, ll s){ fill(ALL(level), -1); queue<ll> que; level[s] = 0; que.push(s); while(!que.empty()){ ll v = que.front(); que.pop(); for(ll i=0; i< G[v].size(); i++){ edgeForFlow &e = G[v][i]; if(e.cap > 0 && level[e.to] < 0){ level[e.to] = level[v] + 1; que.push(e.to); } } } } int dfsDinic(vector<vector<edgeForFlow>> &G, vll &level, vll &iter, ll v, ll t, ll f){ //? iter: record where have been searched? //* v: current vertex, t: sink, f: DELTA of this path. (No need for source) if(v == t) return f; for( ll &i = iter[v]; i < G[v].size(); i++){ edgeForFlow &e = G[v][i]; if( e.cap > 0 && level[v] < level[e.to]){ ll d = dfsDinic(G, level, iter, e.to, t, min(f, e.cap)); if(d > 0){ e.cap -= d; G[e.to][e.rev].cap += d; return d; } } } return 0; //* if no valid outgoing edges } int maxFlowDinic(vector<vector<edgeForFlow>> &G, ll s, ll t){ vll level(G.size()), iter(G.size()); ll flow = 0; for(;;){ bfsDinic(G, level, s); if(level[t] < 0)//* sink t is not reachable from s on current residual graph return flow; fill(ALL(iter), 0); ll f; while((f = dfsDinic(G, level, iter, s, t, INF)) > 0){ flow += f; } } } int main(){ ll N, M, d; cin >> N >> M >> d; vll u(M), v(M), p(M), q(M), w(M); REP(i, M){ scanf("%lld%lld%lld%lld%lld", &u[i], &v[i], &p[i], &q[i], &w[i]); } vector<vector<edgeForFlow>> G(2*M+2); //* source: 2M, sink: 2M+1 REP(i, M){ addEdgeForFlow(G, 2*i, 2*i+1, w[i]); } REP(i, M){ REP(j, M){ if(j == i) continue; if(p[j]>= (q[i]+d) && v[i]==u[j]){ addEdgeForFlow(G, 2*i+1, 2*j, INF); } } } REP(i, M){ if(u[i]==1){ addEdgeForFlow(G, 2*M, 2*i, INF); } if(v[i]==N){ addEdgeForFlow(G, 2*i+1, 2*M+1, INF); } } ll flow; flow = maxFlowDinic(G, 2*M, 2*M+1); cout<< flow << endl; return 0; }