QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#487127 | #1359. Setting Maps | liangbowen | WA | 0ms | 3992kb | C++14 | 2.3kb | 2024-07-22 16:38:14 | 2024-07-22 16:38:14 |
Judging History
answer
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#define mems(x, v) memset(x, v, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;
typedef pair <int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
typedef long double wisdom;
const int N = 2005, inf = 0x3f3f3f3f;
struct Edge {int now, nxt; int w;} e[1919810]; int head[N], hh[N], cur = 1;
void ad(int u, int v, int w) {e[++cur].now = v, e[cur].nxt = head[u], e[cur].w = w, head[u] = cur;}
void add(int u, int v, int w) {ad(u, v, w), ad(v, u, 0);}
namespace G {
int s, t, dis[N];
bool bfs() {
queue <int> q; q.push(s), mems(dis, 0x3f), dis[s] = 0, hh[s] = head[s];
while (!q.empty()) {
int u = q.front(); q.pop();
for (int i = head[u], v; i; i = e[i].nxt) if (e[i].w && dis[u] + 1 < dis[v = e[i].now])
{dis[v] = dis[u] + 1, hh[v] = head[v]; if (v == t) return true; q.push(v);}
}
return false;
}
int dfs(int u, int mxf) {
if (u == t) return mxf; int f = 0;
for (int &i = hh[u], v; i && f < mxf; i = e[i].nxt) if (e[i].w && dis[u] + 1 == dis[v = e[i].now]) {
int w = dfs(v, min(mxf - f, e[i].w)); if (!w) dis[v] = inf;
e[i].w -= w, e[i ^ 1].w += w, f += w;
}
return f;
}
int dinic() {int ans = 0; while (bfs()) ans += dfs(s, inf); return ans;}
}
int n, m, k, s, t; bool vis[N];
inline int in(int u, int t) {return (t - 1) * n + u;} inline int out(int u, int t) {return (t + k - 1) * n + u;}
void getv(int u) {vis[u] = true; for (int i = head[u], v; i; i = e[i].nxt) if (e[i].w && !vis[v = e[i].now]) getv(v);}
int main() {
cin >> n >> m >> k >> s >> t, G::s = 0, G::t = out(n, k) + 1;
for (int i = 1, w; i <= n; i++) {
scanf("%d", &w);
for (int j = 1; j <= k; j++) add(in(i, j), out(i, j), w);
for (int j = 2; j <= k; j++) add(in(i, j - 1), out(i, j), inf);
}
while (m--) {int u, v; scanf("%d%d", &u, &v); for (int i = 1; i <= k; i++) add(out(u, i), in(v, i), inf);}
add(G::s, in(s, 1), inf); for (int i = 1; i <= k; i++) add(out(t, i), G::t, inf);
if (G::dinic() > 1e9) return puts("-1"), 0;
getv(G::s); vector <int> ans;
for (int i = 1; i <= n; i++) for (int j = 1; j <= k; j++) if (vis[in(i, j)] != vis[out(i, j)]) {ans.push_back(i); break;}
printf("%d\n", (int)ans.size()); for (int x : ans) printf("%d ", x);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3992kb
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: 3792kb
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: -100
Wrong Answer
time: 0ms
memory: 3824kb
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:
7 1 5 6 7 8 9 10
result:
wrong answer User answer is not optimal; judge: 60, user: 1060