結果
問題 | No.654 Air E869120 |
ユーザー | umimel |
提出日時 | 2022-10-11 23:39:26 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 39 ms / 2,000 ms |
コード長 | 3,374 bytes |
コンパイル時間 | 2,311 ms |
コンパイル使用メモリ | 199,172 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-25 18:21:07 |
合計ジャッジ時間 | 3,664 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 1 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,948 KB |
testcase_04 | AC | 2 ms
6,944 KB |
testcase_05 | AC | 2 ms
6,944 KB |
testcase_06 | AC | 2 ms
6,944 KB |
testcase_07 | AC | 1 ms
6,944 KB |
testcase_08 | AC | 2 ms
6,944 KB |
testcase_09 | AC | 2 ms
6,940 KB |
testcase_10 | AC | 39 ms
6,944 KB |
testcase_11 | AC | 15 ms
6,940 KB |
testcase_12 | AC | 22 ms
6,944 KB |
testcase_13 | AC | 28 ms
6,940 KB |
testcase_14 | AC | 9 ms
6,940 KB |
testcase_15 | AC | 16 ms
6,940 KB |
testcase_16 | AC | 9 ms
6,944 KB |
testcase_17 | AC | 14 ms
6,940 KB |
testcase_18 | AC | 9 ms
6,940 KB |
testcase_19 | AC | 11 ms
6,940 KB |
testcase_20 | AC | 6 ms
6,944 KB |
testcase_21 | AC | 6 ms
6,940 KB |
testcase_22 | AC | 6 ms
6,940 KB |
testcase_23 | AC | 6 ms
6,944 KB |
testcase_24 | AC | 5 ms
6,944 KB |
testcase_25 | AC | 5 ms
6,944 KB |
testcase_26 | AC | 6 ms
6,940 KB |
testcase_27 | AC | 5 ms
6,940 KB |
testcase_28 | AC | 5 ms
6,940 KB |
testcase_29 | AC | 5 ms
6,944 KB |
testcase_30 | AC | 4 ms
6,940 KB |
testcase_31 | AC | 4 ms
6,940 KB |
testcase_32 | AC | 4 ms
6,940 KB |
testcase_33 | AC | 4 ms
6,944 KB |
testcase_34 | AC | 4 ms
6,944 KB |
testcase_35 | AC | 2 ms
6,944 KB |
testcase_36 | AC | 2 ms
6,944 KB |
testcase_37 | AC | 1 ms
6,940 KB |
testcase_38 | AC | 1 ms
6,944 KB |
testcase_39 | AC | 2 ms
6,940 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; using pll = pair<ll, ll>; #define drep(i, cc, n) for (ll i = (cc); i <= (n); ++i) #define rep(i, n) drep(i, 0, n - 1) #define all(a) (a).begin(), (a).end() #define pb push_back #define fi first #define se second const ll MOD = 1000000007; const ll MOD2 = 998244353; const ll INF = 1LL << 60; const ll MAX_N = 2e5; struct Edge{ ll to; ll cap; ll rev; }; struct Ford_Fulkerson{ vector<vector<Edge>> G; vector<bool> used; ll N; Ford_Fulkerson(vector<vector<pll>> G_){ N = (ll)G_.size(); G.resize(N); used.resize(N, false); rep(from, N){ for(pll p : G_[from]){ ll to = p.fi; ll cap = p.se; G[from].pb((Edge){to, cap, (ll)G[to].size()}); G[to].pb((Edge){from, 0, (ll)(G[from].size()-1)}); } } } ll dfs(ll v, ll t, ll f, vector<vector<Edge>> &H){ if(v == t) return f; used[v] = true; for(ll i=0; i<(ll)H[v].size(); i++){ Edge &e = H[v][i]; if(!used[e.to] && e.cap > 0){ ll d = dfs(e.to, t, min(f, e.cap), H); if(d > 0){ e.cap -= d; H[e.to][e.rev].cap += d; return d; } } } return 0; } ll max_flow(ll s, ll t){ ll flow = 0; vector<vector<Edge>> H(N); rep(from, N) for(Edge e : G[from]) H[from].pb(e); for(;;){ rep(i, N) used[i] = false; ll f = dfs(s, t, INF, H); if(f == 0) return flow; flow += f; } } }; int main(){ ll n, m, d; cin >> n >> m >> d; vector<vector<tuple<ll, ll>>> G_in(n); // (自身のID, 到着時刻) vector<vector<tuple<ll, ll, ll, ll>>> G_out(n); // (自身のID, 相手のID, 出発時刻, 容量) ll cnt = 1; rep(i, m){ ll u, v, p, q, w; cin >> u >> v >> p >> q >> w; u--; v--; if(u == n-1 || v == 0) continue; ll u_id = cnt++; ll v_id = cnt++; G_in[v].pb({v_id, q}); G_out[u].pb({u_id, v_id, p, w}); } cnt++; vector<vector<pll>> G(cnt); for(tuple<ll, ll, ll, ll> tmp : G_out[0]){ ll v = get<0>(tmp); G[0].pb({v, INF}); } for(ll i=1; i<n-1; i++){ for(tuple<ll, ll> tmp1 : G_in[i]){ ll u = get<0>(tmp1); ll p = get<1>(tmp1); for(tuple<ll, ll, ll, ll> tmp2 : G_out[i]){ ll v = get<0>(tmp2); ll q = get<2>(tmp2); if(p + d <= q){ G[u].pb({v, INF}); } } } } for(tuple<ll, ll> tmp : G_in[n-1]){ ll u = get<0>(tmp); G[u].pb({cnt-1, INF}); } for(ll i=0; i<n-1; i++){ for(tuple<ll, ll, ll, ll> tmp : G_out[i]){ ll u = get<0>(tmp); ll v = get<1>(tmp); ll c = get<3>(tmp); G[u].pb({v, c}); } } /* for(ll i=0; i<cnt; i++){ cout << "i : " << i << endl; for(pll x : G[i]){ cout << x.fi << " " << x.se << endl; } cout << endl; } */ Ford_Fulkerson FF(G); cout << FF.max_flow(0, cnt-1) << endl; }