結果
問題 | No.654 Air E869120 |
ユーザー | e869120 |
提出日時 | 2018-01-27 19:29:14 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 6 ms / 2,000 ms |
コード長 | 2,482 bytes |
コンパイル時間 | 1,030 ms |
コンパイル使用メモリ | 94,192 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-09 05:34:07 |
合計ジャッジ時間 | 2,040 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 1 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 1 ms
6,940 KB |
testcase_06 | AC | 1 ms
6,944 KB |
testcase_07 | AC | 2 ms
6,944 KB |
testcase_08 | AC | 1 ms
6,940 KB |
testcase_09 | AC | 2 ms
6,944 KB |
testcase_10 | AC | 5 ms
6,940 KB |
testcase_11 | AC | 4 ms
6,940 KB |
testcase_12 | AC | 5 ms
6,940 KB |
testcase_13 | AC | 5 ms
6,940 KB |
testcase_14 | AC | 5 ms
6,940 KB |
testcase_15 | AC | 4 ms
6,944 KB |
testcase_16 | AC | 5 ms
6,944 KB |
testcase_17 | AC | 6 ms
6,940 KB |
testcase_18 | AC | 5 ms
6,944 KB |
testcase_19 | AC | 6 ms
6,940 KB |
testcase_20 | AC | 5 ms
6,940 KB |
testcase_21 | AC | 4 ms
6,940 KB |
testcase_22 | AC | 3 ms
6,944 KB |
testcase_23 | AC | 5 ms
6,944 KB |
testcase_24 | AC | 5 ms
6,940 KB |
testcase_25 | AC | 4 ms
6,944 KB |
testcase_26 | AC | 4 ms
6,944 KB |
testcase_27 | AC | 4 ms
6,944 KB |
testcase_28 | AC | 4 ms
6,940 KB |
testcase_29 | AC | 4 ms
6,940 KB |
testcase_30 | AC | 4 ms
6,944 KB |
testcase_31 | AC | 4 ms
6,944 KB |
testcase_32 | AC | 4 ms
6,940 KB |
testcase_33 | AC | 4 ms
6,940 KB |
testcase_34 | AC | 4 ms
6,944 KB |
testcase_35 | AC | 2 ms
6,944 KB |
testcase_36 | AC | 1 ms
6,940 KB |
testcase_37 | AC | 1 ms
6,940 KB |
testcase_38 | AC | 2 ms
6,940 KB |
testcase_39 | AC | 1 ms
6,940 KB |
ソースコード
#include <iostream> #include <vector> #include <algorithm> #include <queue> using namespace std; struct edge { long long to, cap, rev; }; class Max_Flow { public: vector<vector<edge>> G; vector<long long>level, iter; void init(long long size_) { G.resize(size_); level.resize(size_); iter.resize(size_); } void add_edge(long long from, long long to, long long cap) { G[from].push_back(edge{ to, cap, (long long)G[to].size() }); G[to].push_back(edge{ from, 0, (long long)G[from].size() - 1 }); } void bfs(long long s) { for (long long i = 0; i < level.size(); i++) level[i] = -1; queue<long long> que; level[s] = 0; que.push(s); while (!que.empty()) { long long v = que.front(); que.pop(); for (long long i = 0; i < 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); } } } } long long dfs(long long v, long long t, long long f) { if (v == t) return f; for (long long &i = iter[v]; i < G[v].size(); i++) { edge &e = G[v][i]; if (e.cap > 0 && level[v] < level[e.to]) { long long 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; } long long max_flow(long long s, long long t) { long long flow = 0; for (;;) { bfs(s); if (level[t] < 0) return flow; for (int i = 0; i < iter.size(); i++) iter[i] = 0; long long f; while ((f = dfs(s, t, (1LL << 60))) > 0) { flow += f; } } } }; long long n, m, p, a[1009], b[1009], c[1009], d[1009], e[1009]; vector<pair<long long, long long>>L; int main() { cin >> n >> m >> p; for (int i = 0; i < m; i++) { cin >> a[i] >> b[i] >> c[i] >> d[i] >> e[i]; d[i] += p; L.push_back(make_pair(a[i], c[i])); L.push_back(make_pair(b[i], d[i])); } sort(L.begin(), L.end()); Max_Flow X; X.init(L.size() + 4); for (int i = 0; i < m; i++) { int pos1 = lower_bound(L.begin(), L.end(), make_pair(a[i], c[i])) - L.begin(); int pos2 = lower_bound(L.begin(), L.end(), make_pair(b[i], d[i])) - L.begin(); X.add_edge(pos1, pos2, e[i]); } for (int i = 1; i < L.size(); i++) { if (L[i].first == L[i - 1].first) X.add_edge(i - 1, i, (1LL << 60)); } for (int i = 0; i < L.size(); i++) { if (L[i].first == 1) X.add_edge(L.size(), i, (1LL << 60)); if (L[i].first == n) X.add_edge(i, L.size() + 1, (1LL << 60)); } cout << X.max_flow(L.size(), L.size() + 1) << endl; return 0; }