結果
問題 |
No.654 Air E869120
|
ユーザー |
![]() |
提出日時 | 2020-09-19 13:12:09 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 22 ms / 2,000 ms |
コード長 | 4,252 bytes |
コンパイル時間 | 2,289 ms |
コンパイル使用メモリ | 149,656 KB |
最終ジャッジ日時 | 2025-01-14 18:43:30 |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 35 |
ソースコード
//#pragma warning(disable:4996) //#include <Windows.h> #include <iostream> #include <vector> #include <limits.h> #include <algorithm> #include <string> #include <math.h> #include <limits.h> #include <queue> #include <map> #include <set> #include <iomanip> #include <bitset> #include <cassert> #include <random> #include <functional> #include <stack> #include <iomanip> #include <cassert> //#include <boost/multiprecision/cpp_int.hpp> #include <complex> #include <cstdio> #include <list> #include <bitset> //#include <stdio.h> //< in.txt > out.txt using namespace std; //std::ios::sync_with_stdio(false); //std::cin.tie(0); const long long MOD = 1e9 + 7; const long long INF = 1e18; typedef long long LL; typedef long double LD; //typedef boost::multiprecision::cpp_int bigint; typedef pair<LL, LL> PLL; typedef pair<int, int> PI; typedef pair<LD, LL> pdl; typedef pair<LD, LD> pdd; typedef vector<LL> VLL; typedef vector<VLL> VVLL; typedef vector<int> VI; typedef vector<vector<int>> VVI; typedef unsigned long long ULL; template<class T> using pqueue = priority_queue<T, vector<T>, function<bool(T, T)>>; template<class T> inline void chmin(T& a, T b) { a = min(a, b); } template<class T> inline void chmax(T& a, T b) { a = max(a, b); } void input(); void solve(); void daminput(); void naive(); void outputinput(); int main() { std::cin.tie(0); std::ios::sync_with_stdio(false); input(); //daminput(); solve(); //naive(); //outputinput(); return 0; } ////////////////////////////////////////////////// ////////////////////////////////////////////////// int N, M, d; VI U, V, P, Q, W; void input() { cin >> N >> M >> d; U.resize(M); V.resize(M); P.resize(M); Q.resize(M); W.resize(M); for (int m = 0; m < M; m++) { cin >> U[m] >> V[m] >> P[m] >> Q[m] >> W[m]; } } void daminput() { } template<class F> class MaxFEdge { public: int to; F cap; int rev; MaxFEdge(int _to, F _cap, int _rev) :to(_to), cap(_cap), rev(_rev) {} }; template<class F> class Dinic { public: int V; vector<vector<MaxFEdge<F>>> G; VI itr, level; Dinic(int _v) :V(_v) { G.resize(V); } void AddEdge(int src, int to, F cap) { G[src].push_back(MaxFEdge<F>(to, cap, G[to].size())); G[to].push_back(MaxFEdge<F>(src, 0, G[src].size() - 1)); } void bfs(int s) { level.assign(V, -1); queue<int> q; level[s] = 0; q.push(s); while (!q.empty()) { int v = q.front(); q.pop(); for (auto& e : G[v]) { if (e.cap > 0 && level[e.to] < 0) { level[e.to] = level[v] + 1; q.push(e.to); } } } } F dfs(int v, int t, F f) { if (v == t)return f; F res = 0; for (int& i = itr[v]; i < (int)G[v].size(); i++) { MaxFEdge<F>& e = G[v][i]; if (e.cap > 0 && level[v] < level[e.to]) { F d = dfs(e.to, t, min(f, e.cap)); if (d > 0) { e.cap -= d; G[e.to][e.rev].cap += d; res += d; f -= d; } } } return res; } F MaxFlow(int s, int t) { F res = 0; F f = 0; F inf = numeric_limits<F>::max(); while (true) { bfs(s); if (level[t] < 0)return res; itr.assign(V, 0); while (true) { f = dfs(s, t, inf); if (f <= 0)break; res += f; } } } }; void solve() { vector<PLL> vers; { set<PLL> versset; versset.insert(PLL(1, 0)); versset.insert(PLL(N, (LL)1e9+(LL)d)); for (int m = 0; m < M; m++) { versset.insert(PI(U[m], P[m])); versset.insert(PI(V[m], Q[m]+d)); } for (PLL pll : versset) { vers.push_back(pll); } sort(vers.begin(), vers.end(), [](PLL a, PLL b) { if (a.first != b.first)return a.first < b.first; else return a.second < b.second; }); } auto conv = [&](PLL a) { int s = -1, e = vers.size(); while (e - s > 1) { int m = (e + s) / 2; if (vers[m].first < a.first)s = m; else if (vers[m].first > a.first)e = m; else if (vers[m].second <= a.second)s = m; else e = m; } return s; }; Dinic<LL> D(vers.size()); for (int m = 0; m < M; m++) { int s = conv(PLL(U[m], P[m])); int e = conv(PLL(V[m], Q[m]+d)); D.AddEdge(s, e, W[m]); } for (int n = 0; n < vers.size()-1; n++) { if (vers[n].first == vers[n + 1].first) { D.AddEdge(n, n + 1, 1e15); } } LL maxflow = D.MaxFlow(0, vers.size() - 1); cout << maxflow << "\n"; } void naive() { } void outputinput() { }