QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#487128#1359. Setting MapsliangbowenWA 2ms4100kbC++142.3kb2024-07-22 16:38:532024-07-22 16:38:53

Judging History

你现在查看的是最新测评结果

  • [2024-07-22 16:38:53]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:4100kb
  • [2024-07-22 16:38:53]
  • 提交

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: 3728kb

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: 3840kb

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: 4100kb

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: 3836kb

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: 3708kb

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: 3768kb

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: 3656kb

input:

2 1 5
1 2
10 10
1 2

output:

-1

result:

ok answer = IMPOSSIBLE

Test #8:

score: 0
Accepted
time: 0ms
memory: 3868kb

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: 3812kb

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: 3780kb

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: 3768kb

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: 2ms
memory: 4036kb

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:

-1

result:

wrong answer User answer is not optimal; judge: 2000000000, user: 2000000010