結果
| 問題 |
No.654 Air E869120
|
| コンテスト | |
| ユーザー |
kaikey
|
| 提出日時 | 2020-06-02 15:47:22 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 381 ms / 2,000 ms |
| コード長 | 2,992 bytes |
| コンパイル時間 | 2,142 ms |
| コンパイル使用メモリ | 185,036 KB |
| 実行使用メモリ | 183,296 KB |
| 最終ジャッジ日時 | 2024-11-24 01:00:54 |
| 合計ジャッジ時間 | 8,712 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 35 |
ソースコード
#include "bits/stdc++.h"
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define Alint(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1ll << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 998244353, INF = 1e18 ;
struct edge { lint to, cap, rev; };
vector<edge> Graph[2000010];
int level[2000010];
int iter[2000010];
void add_edge(lint from, lint to, lint cap) {
Graph[from].push_back({ to, cap, SZ(Graph[to]) });
Graph[to].push_back({ from, 0, SZ(Graph[from]) - 1 });
}
void bfs(lint s) {
memset(level, -1, sizeof(level));
queue<lint> que;
que.push(s);
level[s] = 0;
while (!que.empty()) {
lint v = que.front(); que.pop();
REP(i, SZ(Graph[v])) {
edge& e = Graph[v][i];
if (e.cap > 0 && level[e.to] < 0) {
level[e.to] = level[v] + 1;
que.push(e.to);
}
}
}
}
lint dfs(lint v, lint t, lint f) {
if (v == t) return f;
for (int& i = iter[v]; i < SZ(Graph[v]); i++) {
edge& e = Graph[v][i];
if (e.cap > 0 && level[v] < level[e.to]) {
lint d = dfs(e.to, t, min(f, e.cap));
if (d > 0) {
e.cap -= d;
Graph[e.to][e.rev].cap += d;
return d;
}
}
}
return 0;
}
lint max_flow(lint s, lint t) {
lint flow = 0;
for (;;) {
bfs(s);
if (level[t] < 0) return flow;
memset(iter, 0, sizeof(iter));
lint f;
while ((f = dfs(s, t, INF)) > 0) {
flow += f;
}
}
}
lint N, M, D;
lint u[1000], v[1000], p[1000], q[1000], w[1000];
map<lint, lint> toidx_t;
set<lint> st;
const lint MAX = pow(10, 9);
int main() {
cin.tie(0); ios_base::sync_with_stdio(false);
cin >> N >> M >> D;
st.insert(0); st.insert(MAX);
REP(i, M) {
cin >> u[i] >> v[i] >> p[i] >> q[i] >> w[i]; u[i]--; v[i]--;
st.insert(p[i]);
st.insert(min(q[i] + D, MAX));
}
//座圧
lint idx = 0;
for (auto itr : st) {
toidx_t[itr] = idx;
idx++;
}
//二次元情報(街番号(i)、時間(t))を一次元情報に圧縮する
// Info = i*idx + f(t)
REP(i, M) {
add_edge(u[i] * idx + toidx_t[p[i]], v[i] * idx + toidx_t[min(q[i] + D, MAX)], w[i]);
}
//同じ街に対して時間に沿った有向辺を張る
REP(i, N) {
REP(j, idx - 1) {
add_edge(i * idx + j, i * idx + j + 1, INF);
}
}
cout << max_flow(0, N * idx - 1);
}
kaikey