QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#110102 | #1359. Setting Maps | c20230135 | WA | 3ms | 7716kb | C++14 | 2.0kb | 2023-05-31 15:27:35 | 2023-05-31 15:27:39 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int R = 205, K = 6, N = 100005, M = 2000005;
const ll inf = 1e10 + 5;
int n, m, k, cnt, tot = 1, st, ed, s, t, num;
int in[R][K], out[R][K];
int fir[N], ver[M], nxt[M], d[N], v[N], ans[R];
ll edge[M], 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, &st, &ed);
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[st][0];
for (int j = 0; j < k; j++) add(out[ed][j], t, inf);
while (bfs()) while ((flow = dinic(s, inf))) mincut += flow;
if (mincut >= inf) return printf("-1"), 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < k; j++) {
if (d[in[i][j]] && !d[out[i][j]]) { ans[++num] = i; break; }
}
}
printf("%d\n", num);
for (int i = 1; i <= num; i++) printf("%d ", ans[i]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 7716kb
input:
3 2 5 1 3 1 60 35 1 2 2 3
output:
-1
result:
ok answer = IMPOSSIBLE
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 7684kb
input:
7 11 1 1 7 100 5 7 16 11 12 100 1 2 1 3 1 4 1 5 2 3 2 6 3 6 4 3 4 7 5 7 6 7
output:
0
result:
wrong answer Given vertex set from user output does not cover k vertices in some path