QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#563125 | #3249. 分组作业 | Elegia | AC ✓ | 34ms | 6884kb | C++23 | 3.5kb | 2024-09-14 02:58:57 | 2024-09-14 02:58:58 |
Judging History
answer
/*
不, 我想亲眼看看自己选择的终点是什么样的地方.
*/
#include <cmath>
#include <cstring>
#include <algorithm>
#include <limits>
#include <functional>
#include <random>
#include <chrono>
#include <stack>
#include <bitset>
#include <numeric>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <unordered_map>
using ull = unsigned long long;
using ll = long long;
using namespace std;
mt19937 rng(chrono::steady_clock().now().time_since_epoch().count());
const int P = 998244353;
int norm(int x) { return x >= P ? x - P : x; }
int reduce(int x) { return x < 0 ? x + P : x; }
int neg(int x) { return x ? P - x : 0; }
void add(int& x, int y) { if ((x += y - P) < 0) x += P; }
void sub(int& x, int y) { if ((x -= y) < 0) x += P; }
void fam(int& x, int y, int z) { x = (x + y * (ull)z) % P; }
int mpow(int x, unsigned k) {
if (k == 0) return 1;
int ret = mpow(x * (ull)x % P, k >> 1);
if (k & 1) ret = ret * (ull)x % P;
return ret;
}
template<class Z>
struct MaxFlow {
vector<vector<tuple<int, int, Z>>> g;
struct Ref {
const MaxFlow *p;
int u, id;
Ref() {}
Ref(const MaxFlow *p, int u, int id) : p(p), u(u), id(id) {}
Z get() const { return std::get<2>((p->g)[u][id]); }
};
MaxFlow() {}
MaxFlow(int n) : g(n) {}
Ref addEdge(int u, int v, const Z &w) {
if (u == v) return Ref();
int ru = g[u].size(), rv = g[v].size();
g[u].emplace_back(v, rv, w);
g[v].emplace_back(u, ru, 0);
return Ref(this, v, rv);
}
Z dinic(int s, int t) {
int n = g.size();
function<vector<int>()> getLevel = [&]() {
vector<int> level(n, -1);
queue<int> q;
level[s] = 0;
q.push(s);
while (!q.empty()) {
int u = q.front();
q.pop();
for (const auto &pr : g[u])
if (get<2>(pr) && level[get<0>(pr)] == -1) {
level[get<0>(pr)] = level[u] + 1;
q.push(get<0>(pr));
}
}
return level;
};
vector<int> r, level;
function<Z(int, Z)> cap = [&](int u, Z limit) {
if (u == t) return limit;
Z ret = 0;
while (r[u] && limit > ret) {
int v = get<0>(g[u][r[u] - 1]), rev = get<1>(g[u][r[u] - 1]);
Z &w = get<2>(g[u][r[u] - 1]);
if (level[v] == level[u] + 1) {
Z flow = cap(v, min(limit - ret, w));
ret += flow;
w -= flow;
get<2>(g[v][rev]) += flow;
if (limit == ret)
return ret;
--r[u];
} else
--r[u];
}
return ret;
};
Z ret = 0;
while (level = getLevel(), level[t] != -1) {
r = vector<int>(n);
for (int i = 0; i < n; ++i)
r[i] = g[i].size();
ret += cap(s, numeric_limits<Z>::max());
}
return ret;
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int N, M; cin >> N >> M;
MaxFlow<long long> flow(N * 3 + 2);
int s = N * 3, t = s + 1;
for (int i = 0; i != N * 2; ++i) {
int c, d, e; cin >> c >> d >> e;
flow.addEdge(s, i, c); flow.addEdge(i, t, d);
flow.addEdge(i ^ 1, i, e);
}
for (int i = 0; i != N; ++i) {
flow.addEdge(i * 2, N * 2 + i, 1e18);
flow.addEdge(i * 2 + 1, N * 2 + i, 1e18);
}
while (M--) {
int A, B, a, b; cin >> A >> B >> a >> b; --A; --B;
flow.addEdge(N * 2 + A / 2, B, a);
flow.addEdge(A, N * 2 + B / 2, b);
}
cout << flow.dinic(s, t) << '\n';
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 33ms
memory: 6876kb
input:
5000 10000 23060775 12 2 255978380 28 517 5 6624 26 151149 45131806 23849036 489 484971 24970 162846 1993316 188305 56311199 2003 211 1 50534913 517527 364913 882765 298 71 26 122914059 13 65459 18150033 20 607 8 380059068 3873712 228 9813 5449 6370 3309369 37410691 8 181 1 62340851 1705 4 107 8 209...
output:
22929674417
result:
ok single line: '22929674417'
Test #2:
score: 0
Accepted
time: 33ms
memory: 6884kb
input:
5000 10000 10055 16 122 4784525 16 23548777 75 3 412576 26487664 16119952 1092 3168 28 16059 33 4 13 2 1319671 7150391 17548 31559813 3201 6910 499901569 2 86633 8794940 2 4 2 85 1749 9908314 45526 10 631569 2347 18 141185 145333 23 27 117121 3825480 32645 5236 3 32022 1298 8 51750221 233 4 16102047...
output:
21306827991
result:
ok single line: '21306827991'
Test #3:
score: 0
Accepted
time: 34ms
memory: 6824kb
input:
5000 10000 48362 83079 12461784 16 4689773 2 763 3650 1128 2118 75447925 253189 47745409 622140 70841 302 162849091 1258 3399198 91 808632 16168406 10380 2 370511 10 3193109 261594 4 2 128 106331221 2 605 28343 601 19 1224480 37551173 49 78375152 493909 110536 1 836 28790 8 133 8 40 4 533035 879 391...
output:
22066314160
result:
ok single line: '22066314160'
Test #4:
score: 0
Accepted
time: 31ms
memory: 6756kb
input:
5000 10000 5564 607330 2584640 126520704 169669 3 231555 402303 114 2 128 58 290016 13 74249 8126414 279 974 1304 119651095 35466664 992290 3414 63 23564 1091 18168 418 125135735 3 29 1295683 424396930 1993 12647005 20 7 712237 1086773 500004515 6 355786 383393 486213 73 21141 29726 665 1 59959 2020...
output:
22438919820
result:
ok single line: '22438919820'
Test #5:
score: 0
Accepted
time: 30ms
memory: 6740kb
input:
5000 10000 23 1 217 41 249931 61567 3096055 3 7 24 12529 1 246322439 144141318 223606 39 906 2 22654307 3963932 3447414 7949665 51935780 344666 30 5058423 2825 148134 7532713 1140 242 5560395 4264 62940 8262918 182 7825 9865191 2992 138038614 24828018 33318812 11 1 4741355 241 533 3 4337359 741573 3...
output:
21645286114
result:
ok single line: '21645286114'
Test #6:
score: 0
Accepted
time: 33ms
memory: 6744kb
input:
5000 10000 53751618 18 124436 857 472 16 13506752 72 6929805 1313173 1 8 13 3 9428917 114702 15875684 375277 95772377 1 19 46 146 544774 2606 90182736 313 2 26253 330 92 17290550 229451029 53 3175 2 48316557 38441802 31 52027 40844521 966 2 455 40909310 6556 6662246 17592087 4914675 39 11812 4590536...
output:
24730200863
result:
ok single line: '24730200863'
Test #7:
score: 0
Accepted
time: 27ms
memory: 6772kb
input:
5000 10000 529152667 2028658 288974 46 2 1853274 212853 4442959 1 7439830 113977860 15476191 87430 6 972573 112375 4489 485 1273959 4049 4059 21 39694709 5 15511 256587916 2 164834468 4 95557537 9330 3 31231 1880144 197069 5753237 102274889 2187511 108044 1906 76869460 12 30311 27016904 6492296 1645...
output:
21376330041
result:
ok single line: '21376330041'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
3 2 1 1 999 1 1 999 1 999 999 1 999 999 999 1 999 999 1 999 5 1 999 1 1 3 100 1
output:
106
result:
ok single line: '106'