QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#110105 | #1359. Setting Maps | c20230135 | WA | 2ms | 3672kb | C++14 | 1.9kb | 2023-05-31 15:34:01 | 2023-05-31 15:34:03 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int R = 205, K = 6, N = 10005;
const ll inf = 1e10 + 5;
int n, m, k, cnt, tot = 1, S, E, s, t;
int in[R][K], out[R][K], d[N], v[N];
int fir[N], ver[N], nxt[N];
ll edge[N], flow, mincut;
bool bfs() {
queue<int> q;
for (int i = 1; i <= cnt; i++) d[i] = 0;
d[s] = 1, q.push(s);
while (q.size()) {
int x = q.front(); q.pop();
for (int i = fir[x], y; i; i = nxt[i]) {
if (!d[y = ver[i]] && edge[i]) {
d[y] = d[x] + 1, q.push(y);
if (y == t) return true;
}
}
}
return false;
}
ll dinic(int x, ll flow) {
if (x == t) return flow;
ll rst = flow;
for (int i = fir[x], y; i && rst; i = nxt[i]) {
if (d[y = ver[i]] == d[x] + 1 && edge[i]) {
ll k = dinic(y, min(rst, edge[i]));
if (!k) d[y] = 0;
edge[i] -= k, edge[i ^ 1] += k, rst -= k;
}
}
return flow - rst;
}
void add(int x, int y, ll z) {
ver[++tot] = y, edge[tot] = z, nxt[tot] = fir[x], fir[x] = tot;
ver[++tot] = x, edge[tot] = 0, nxt[tot] = fir[y], fir[y] = tot;
}
int main() {
scanf("%d%d%d%d%d", &n, &m, &k, &S, &E);
for (int c, i = 1; i <= n; i++) {
scanf("%d", &c);
for (int j = 0; j < k; j++) {
in[i][j] = ++cnt, out[i][j] = ++cnt;
add(in[i][j], out[i][j], c);
}
}
for (int i = 1; i <= n; i++) {
for (int j = 0; j < k - 1; j++)
add(in[i][j], out[i][j + 1], inf);
}
for (int x, y, i = 1; i <= m; i++) {
scanf("%d%d", &x, &y);
for (int j = 0; j < k; j++)
add(out[x][j], in[y][j], inf);
}
s = in[S][0], t = ++cnt;
for (int j = 0; j < k; j++) add(out[E][j], t, inf);
while (bfs()) while ((flow = dinic(s, inf))) mincut += flow;
if (mincut >= inf) printf("-1");
vector<int> ans;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < k; j++)
if (d[in[i][j]] && !d[out[i][j]]) { ans.push_back(i); break; }
}
printf("%d\n", ans.size());
for (int x: ans) printf("%d ", x);
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 3672kb
input:
3 2 5 1 3 1 60 35 1 2 2 3
output:
-11 1
result:
wrong answer Integer parameter [name=p; number of vertices] equals to -11, violates the range [-1, 3]