結果
問題 | No.654 Air E869120 |
ユーザー |
|
提出日時 | 2022-10-11 23:39:26 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.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 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 35 |
ソースコード
#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 secondconst 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;}