QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#30456 | #3855. Regional development | whereismyteammate# | TL | 1ms | 3676kb | C++20 | 1.4kb | 2022-04-28 20:39:28 | 2022-04-28 20:39:30 |
Judging History
answer
#include <bits/stdc++.h>
const int N = 1005;
int n, m, p, pre[N];
int a[N], b[N], c[N], out[N];
std::vector<int> G[N];
bool vis[N];
int dfs(int x) {
vis[x] = true;
if (out[x] > 0)
return x;
for (int e_id : G[x]) {
int end_point = (c[e_id] > 0 ? a[e_id] : b[e_id]);
if (end_point == x || pre[end_point] || vis[end_point]) {
continue;
}
pre[end_point] = e_id;
if (int t = dfs(end_point); t != -1)
return t;
}
return -1;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
std::cin >> n >> m >> p;
for (int i = 1; i <= m; ++i) {
std::cin >> a[i] >> b[i] >> c[i];
G[a[i]].push_back(i);
G[b[i]].push_back(i);
out[a[i]] += c[i];
out[b[i]] -= c[i];
}
auto assign = [&](int e, int v) {
out[a[e]] -= c[e];
out[b[e]] += c[e];
c[e] = v;
out[a[e]] += c[e];
out[b[e]] -= c[e];
};
for (int x = 1; x <= n; ++x) {
while (out[x] < 0) {
memset(pre, 0, sizeof pre);
memset(vis, 0, sizeof vis);
int y = dfs(x);
assert(y != -1);
while (pre[y]) {
int e = pre[y];
if (a[e] == y) {
assign(e, c[e] - p);
y = b[e];
}
else {
assert(b[e] == y);
assign(e, c[e] + p);
y = a[e];
}
}
}
assert(out[x] >= 0);
}
for (int i = 1; i <= m; ++i) {
std::cout << c[i] << '\n';
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3676kb
input:
10 23 3 2 10 1 2 6 1 6 9 1 7 9 1 6 7 1 3 6 1 1 3 1 1 6 2 6 10 1 2 9 1 4 9 2 4 7 2 3 10 2 3 9 1 6 8 1 7 8 2 3 5 1 5 9 1 8 9 2 3 8 2 1 5 2 1 4 1 5 10 2
output:
-2 1 1 -2 -2 -2 -2 -1 -2 1 -1 2 2 -2 1 2 1 1 2 -1 2 1 2
result:
ok correct plan
Test #2:
score: -100
Time Limit Exceeded
input:
100 1297 11 27 34 5 7 34 6 7 90 3 80 90 6 37 80 6 37 48 5 47 48 6 47 86 5 56 86 6 56 84 5 63 84 6 38 63 6 66 91 8 12 91 6 12 15 5 15 22 1 22 87 5 46 87 6 46 63 10 63 87 8 71 87 6 65 71 6 38 65 1 38 67 4 29 67 6 9 29 6 9 21 5 16 21 6 16 89 2 89 98 5 4 98 6 4 13 4 13 33 5 14 33 6 14 66 10 66 86 10 57 ...