QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#282211#1359. Setting MapsjeefyWA 1ms5880kbC++143.8kb2023-12-11 16:28:202023-12-11 16:28:21

Judging History

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

  • [2023-12-11 16:28:21]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5880kb
  • [2023-12-11 16:28:20]
  • 提交

answer

#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>

using namespace std;
using lint = long long;
const lint inf = 2e18;

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 + 7, M = 1000 + 7, K = 50 + 7;

ISAP<lint, N * K, M * K + N * K> 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);
		}
	}
	
	for (int i = 0; i < k; ++i) isap.add(out[t][i], 0, inf);
	if (isap.maxflow(use, in[s][0], 0) > inf / 2) {
		cout << -1 << '\n';
		return 0;
	} 
	
	queue<int> q;
	q.push(in[s][0]), vis[in[s][0]] = true;
	while (q.size()) {
		int x = q.front(); q.pop();
		for (int i = isap.head[x]; i; i = isap.nxt[i]) {
			int y = isap.to[i];
			if (!vis[y] && isap.fl[i]) vis[y] = true, q.push(y);
		}
	}
	
	for (int i = 1; i <= n; ++i) {
		for (int j = 0; j < k; ++j)
			if (vis[in[i][j]] && !vis[out[i][j]]) cut[i] = true;
	}
	
	int cnt = 0, ans = 0;
	for (int i = 1; i <= n; ++i) {
		if (cut[i]) ++cnt, ans += C[i];
	}
	
//	cout << ans << '\n';
	cout << cnt << '\n';
	for (int i = 1; i <= n; ++i) {
		if (cut[i]) cout << i << ' ';
	}
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 5880kb

input:

3 2 5
1 3
1 60 35
1 2
2 3

output:

0

result:

wrong answer Given vertex set from user output does not cover k vertices in some path