結果
| 問題 |
No.654 Air E869120
|
| コンテスト | |
| ユーザー |
303Yuyu
|
| 提出日時 | 2021-02-12 21:45:51 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 11 ms / 2,000 ms |
| コード長 | 3,384 bytes |
| コンパイル時間 | 2,086 ms |
| コンパイル使用メモリ | 182,540 KB |
| 実行使用メモリ | 6,272 KB |
| 最終ジャッジ日時 | 2024-07-19 20:54:32 |
| 合計ジャッジ時間 | 3,650 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 35 |
ソースコード
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using ld = long double;
using vld = vector<ld>;
using vb = vector<bool>;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define dbg(x) true
#endif
template <class T> bool chmin(T& a, T b) {
if(a > b) { a = b; return true; }
else return false;
}
template <class T> bool chmax(T& a, T b) {
if(a < b) { a = b; return true; }
else return false;
}
template <class T> ostream& operator<<(ostream& s, const vector<T>& a) {
for(auto i : a) s << i << ' ';
return s;
}
constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);
struct Edge {
ll to, cap, rev;
Edge(ll to, ll cap, ll rev) : to(to), cap(cap), rev(rev) {};
};
struct Dinic {
ll n;
vector<vector<Edge>> g;
vector<ll> level, iter;
Dinic(ll n) : n(n), g(n), iter(n) {};
void add_edge(ll from, ll to, ll cap) {
g[from].emplace_back(to, cap, (ll)g[to].size());
g[to].emplace_back(from, 0, (ll)g[from].size()-1);
}
// 容量が残っているパスにおける始点からの距離を計算
void bfs(ll s) {
level.assign(n, -1);
queue<ll> que;
level[s] = 0;
que.push(s);
while(!que.empty()) {
ll v = que.front();
que.pop();
for(ll i = 0; i < (ll)g[v].size(); ++i) {
Edge& e = g[v][i];
if(e.cap > 0 && level[e.to] < 0) {
level[e.to] = level[v] + 1;
que.push(e.to);
}
}
}
}
// levelが増えるパスにおけるflowを計算
ll dfs(ll v, ll t, ll f) {
if(v == t) return f;
// iter[v]を増やすことで各Edgeの探査は1回のみとする
for(ll& i = iter[v]; i < (ll)g[v].size(); ++i) {
Edge& e = g[v][i];
if(e.cap > 0 && level[v] < level[e.to]) {
ll d = dfs(e.to, t, min(f, e.cap));
if(d > 0) {
e.cap -= d;
g[e.to][e.rev].cap += d;
return d;
}
}
}
return 0;
}
ll max_flow(ll s, ll t) {
ll flow = 0;
while(true) {
bfs(s);
if(level[t] < 0) return flow;
iter.assign(n, 0);
ll f;
while((f = dfs(s, t, INFL)) > 0) { flow += f; }
}
}
};
void solve() {
ll n, m, d;
cin >> n >> m >> d;
vll u(m), v(m), p(m), q(m), w(m);
rep(i, m) cin >> u[i] >> v[i] >> p[i] >> q[i] >> w[i];
Dinic D(2*m+2);
rep(i, m) {
D.add_edge(i, i+m, w[i]);
if(u[i] == 1) D.add_edge(2*m, i, w[i]);
if(v[i] == n) D.add_edge(i+m, 2*m+1, w[i]);
}
rep(fr, m) rep(to, m) {
if(v[fr] == u[to] && q[fr] + d <= p[to]) {
D.add_edge(fr+m, to, max(w[fr], w[to]));
}
}
cout << D.max_flow(2*m, 2*m+1) << endl;
return;
}
int main() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
cout << fixed << setprecision(15);
solve();
}
303Yuyu