QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#282171 | #1359. Setting Maps | jeefy | WA | 1ms | 4072kb | C++14 | 3.5kb | 2023-12-11 15:44:52 | 2023-12-11 15:44:52 |
Judging History
answer
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
const int inf = 1e9;
template<typename sint, int N, int M>
class ISAP {
public:
sint fl[M * 2];
int to[M * 2], nxt[M * 2], head[N], now[N];
int dep[N], gap[N * 2], use;
int n, S, T;
ISAP() : use(1) {}
inline void add(int x, int y, sint w, int z = 0) {
// cerr << "Add " << x << " -> " << y << " w: " << w << '\n';
/* x -> y */ to[++use] = y, fl[use] = w, nxt[use] = head[x], head[x] = use;
/* y -> x */ to[++use] = x, fl[use] = w*z, nxt[use] = head[y], head[y] = use;
}
void init() {
fill_n(dep, n + 2, -1), fill_n(gap, n + 2, 0);
queue<int> q; q.push(T), ++gap[dep[T] = 0];
while (q.size()) {
int x = q.front(); q.pop(); now[x] = head[x];
// cerr << "Dep " << x << " = " << dep[x] << '\n';
for (int i = head[x]; i; i = nxt[i]) {
if (dep[to[i]] != -1) continue;
++gap[dep[to[i]] = dep[x] + 1], q.push(to[i]);
}
}
}
sint sap(int x, sint flow) {
// cerr << "Sap in " << x << " flow " << flow << '\n';
if (x == T) return flow;
sint rest = flow;
// for (int &i = now[x]; i; i = nxt[i]) {
for (int i = head[x]; i; i = nxt[i]) {
if (dep[to[i]] + 1 != dep[x] || !fl[i]) continue;
int push = sap(to[i], min(rest, fl[i]));
fl[i] -= push, fl[i ^ 1] += push, rest -= push;
if (!rest) return flow;
}
if (--gap[dep[x]] == 0) dep[S] = n + 1;
now[x] = head[x], ++gap[++dep[x]];
return flow - rest;
}
void dfs(int x, int *vis) {
vis[x] = true;
for(int i = head[x]; i; i = nxt[i]) {
if (vis[to[i]] != 1 && fl[i]) dfs(to[i], vis);
if (!vis[to[i]] && !fl[i]) vis[to[i]] = 2;
}
}
sint maxflow(int _n, int s, int t) {
// cerr << "calc S, T: " << s << ", " << t << '\n';
n = _n, S = s, T = t, init();
sint flow = 0;
while (dep[S] <= n) flow += sap(S, inf);
return flow;
}
};
const int N = 200, M = 1000, K = 51;
ISAP<int, N * K, M * K + N * K * 2> isap;
int dep[N], C[N], cut[N], in[N][K], out[N][K], vis[N * K];
vector<int> G[N];
int main() {
// freopen("apers.in", "r", stdin);
// freopen("apers.out", "w", stdout);
cin.tie(0)->sync_with_stdio(false);
int n, m, k; cin >> n >> m >> k;
int s, t; cin >> s >> t;
for (int i = 1; i <= n; ++i) cin >> C[i];
for (int x, y, i = 1; i <= m; ++i) {
cin >> x >> y; G[x].push_back(y);
}
queue<int> q; q.push(s), dep[s] = 1;
while (q.size()) {
int x = q.front(); q.pop();
for (int y : G[x]) {
if (!dep[y]) dep[y] = dep[x] + 1, q.push(y);
}
}
if (dep[t] < k) {
puts("-1"); return 0;
}
int use = 0;
for (int i = 1; i <= n; ++i) {
for (int j = 0; j < k; ++j) {
in[i][j] = ++use, out[i][j] = ++use;
isap.add(in[i][j], out[i][j], C[i]);
}
}
for (int x = 1; x <= n; ++x) {
for (int i = 1; i < k; ++i) {
isap.add(in[x][i - 1], out[x][i], inf);
}
for (int y : G[x]) {
for (int i = 0; i < k; ++i)
isap.add(out[x][i], in[y][i], inf);
}
}
cerr << isap.maxflow(use, in[s][0], out[t][k - 1]) << '\n';
// return 0;
isap.dfs(in[s][0], vis);
for (int i = 1; i <= n; ++i) {
for (int j = 0; j < k; ++j) {
int x = in[i][j], y = out[i][j];
if (vis[x] != 1 || vis[y] != 2) continue;
for (int e = isap.head[x]; e; e = isap.nxt[e]) {
if (isap.to[e] == y && isap.fl[e] == 0) cut[i] = true;
}
}
}
int cnt = 0;
for (int i = 1; i <= n; ++i) {
if (cut[i]) ++cnt;
} cout << cnt << '\n';
for (int i = 1; i <= n; ++i) {
if (cut[i]) cout << i << ' ';
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3540kb
input:
3 2 5 1 3 1 60 35 1 2 2 3
output:
-1
result:
ok answer = IMPOSSIBLE
Test #2:
score: 0
Accepted
time: 0ms
memory: 3692kb
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:
4 2 3 4 5
result:
ok answer = 39
Test #3:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
11 17 2 1 11 1000 10 10 10 10 10 10 10 10 10 1000 1 2 1 3 1 4 1 5 1 6 2 7 3 7 4 7 5 8 6 8 7 8 7 9 7 10 8 9 8 11 9 11 10 11
output:
6 5 6 7 8 9 10
result:
ok answer = 60
Test #4:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
2 2 2 2 1 100 200 1 2 2 1
output:
2 1 2
result:
ok answer = 300
Test #5:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
5 5 5 1 5 1 1 1 1 1 1 2 2 3 3 4 4 5 1 5
output:
-1
result:
ok answer = IMPOSSIBLE
Test #6:
score: 0
Accepted
time: 0ms
memory: 3872kb
input:
100 120 5 1 5 5367720 2854323 1799056 9744604 3215334 7580413 6269402 3208439 8812449 3297484 2047196 4044341 7514502 2928715 9335004 3935096 6660663 3356480 4801491 5786147 895995 6710240 222342 4469390 1543213 6678041 8838445 6741919 8138951 5273670 8983795 5131484 4245746 7460466 8357966 8464419 ...
output:
-1
result:
ok answer = IMPOSSIBLE
Test #7:
score: 0
Accepted
time: 0ms
memory: 3872kb
input:
2 1 5 1 2 10 10 1 2
output:
-1
result:
ok answer = IMPOSSIBLE
Test #8:
score: 0
Accepted
time: 0ms
memory: 3672kb
input:
154 304 2 67 7 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 100000...
output:
2 7 67
result:
ok answer = 20000000
Test #9:
score: 0
Accepted
time: 0ms
memory: 3908kb
input:
75 146 1 15 2 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 1000000...
output:
1 15
result:
ok answer = 10000000
Test #10:
score: 0
Accepted
time: 0ms
memory: 3668kb
input:
182 360 4 97 110 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 1000...
output:
-1
result:
ok answer = IMPOSSIBLE
Test #11:
score: 0
Accepted
time: 0ms
memory: 3872kb
input:
136 268 5 132 5 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000...
output:
-1
result:
ok answer = IMPOSSIBLE
Test #12:
score: -100
Wrong Answer
time: 1ms
memory: 4072kb
input:
200 396 3 174 124 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 100...
output:
3 1 2 174
result:
wrong answer Given vertex set from user output does not cover k vertices in some path