QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#401888#1359. Setting MapsieeWA 0ms3884kbC++142.5kb2024-04-29 16:09:422024-04-29 16:09:43

Judging History

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

  • [2024-04-29 16:09:43]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3884kb
  • [2024-04-29 16:09:42]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
constexpr int inf = 2e9;
int S, T;
struct MF {
	static constexpr int N = 2005;
	struct Edge {
		int v, f;
	};
	vector<int> e[N];
	vector<Edge> l;
	int dis[N];
	bool BFS() {
		memset(dis, -1, sizeof dis);
		queue<int> Q;
		Q.push(S);
		dis[S] = 0;
		while (!Q.empty()) {
			int u = Q.front();
			Q.pop();
			for (int id : e[u]) {
				auto [v, f] = l[id];
				if (f && dis[v] == -1) {
					dis[v] = dis[u] + 1;
					Q.push(v);
				}
			}
		}
		return dis[T] != -1;
	}
	int cur[N];
	int DFS(int u, int limit) {
		if (u == T) return limit;
		int flow = 0;
		for (int i = cur[u]; i < e[u].size() && flow < limit; i = max(i + 1, cur[u])) {
			cur[u] = i + 1;
			int id = e[u][i];
			auto &[v, f] = l[id];
			if (f && dis[v] == dis[u] + 1) {
				int fl = DFS(v, min(limit - flow, f));
				flow += fl;
				f -= fl;
				l[id ^ 1].f += fl;
				if (!fl) dis[v] = -1;
			}
		}
		return flow;
	}
	int Dinic() {
		int flow = 0, fs = 0;
		while (BFS()) {
			fs = 1;
			memset(cur, 0, sizeof cur);
			flow += DFS(S, inf);
		}
		return fs ? flow : inf;
	}
	void add(int u, int v, int f) {
		e[u].push_back(l.size());
		l.push_back({v, f});
		e[v].push_back(l.size());
		l.push_back({u, 0});
	}
	vector<array<int, 2>> cut() {
		int w = Dinic();
		if (w == inf) {
			cout << -1 << "\n";
			exit(0);
		}
		cerr << "w = " << w << endl;
		vector<array<int, 2>> res;
		for (int i = 0; i < l.size(); i += 2) {
			int u = l[i + 1].v, v = l[i].v;
			if (dis[u] != -1 && dis[v] == -1) {
				res.push_back({u, v});
			}
		}
		return res;
	}
} g;
int main() {
	int n, m, K;
	cin >> n >> m >> K;
	int s, t;
	cin >> s >> t, s--, t--;
	auto id = [&](int u, int level, int op) {
		return u * K * 2 + level * 2 + op;
	};
	vector<int> w(n);
	for (int &x : w) {
		cin >> x;
	}
	vector<array<int, 2>> edges(m);
	for (auto &[u, v] : edges) {
		cin >> u >> v;
		u--;
		v--;
	}
	for (int k = 0; k < K; k++) {
		for (int u = 0; u < n; u++) {
			g.add(id(u, k, 0), id(u, k, 1), w[u]);
			if (k + 1 < K) g.add(id(u, k, 0), id(u, k + 1, 1), inf);
		}
		for (auto [u, v] : edges) {
			g.add(id(u, k, 1), id(v, k, 0), inf);
		}
		if (k + 1 < K) g.add(id(t, k, 1), id(t, k + 1, 1), inf);
	}
	S = id(s, 0, 0), T = id(t, K - 1, 1);
	auto res = g.cut();
	vector<int> vec;
	for (auto [u, v] : res) {
		vec.push_back(u / (K * 2));
	}
	cout << vec.size() << "\n";
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] + 1 << " \n"[i + 1 == vec.size()];
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3804kb

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

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

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

input:

2 2 2
2 1
100 200
1 2
2 1

output:

2
2 1

result:

ok answer = 300

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 3884kb

input:

5 5 5
1 5
1 1 1 1 1
1 2
2 3
3 4
4 5
1 5

output:

2
1 1

result:

FAIL duplicate vertex used in user output