QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#282117#1359. Setting MapsJerryJohnWA 1ms3532kbC++141.7kb2023-12-11 13:45:402023-12-11 13:45:41

Judging History

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

  • [2023-12-11 13:45:41]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3532kb
  • [2023-12-11 13:45:40]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int inf = 0x3f3f3f3f3f3f3f3f,N = 1000,M = 10000;
int usv;
int bgn[N + 11],to[2 * M + 11],nxt[2 * M + 11],c[2 * M + 11],u[2 * M + 11],idx = 1;
inline void add(int x,int y,int w)
{
	to[++idx] = y,u[idx] = 0,c[idx] = w,nxt[idx] = bgn[x],bgn[x] = idx;
	to[++idx] = x,u[idx] = 0,c[idx] = 0,nxt[idx] = bgn[y],bgn[y] = idx;
}
int deep[N + 11],nbgn[N + 11];
int flow,S,T;
int q[N + 11],l,r;
inline bool BFS()
{
	for(int i = 1;i <= usv;i++) deep[i] = 0,nbgn[i] = bgn[i];
	deep[S] = 1;
	q[l = 0] = S,r = 1;
	while(l ^ r)
	{
		int p = q[l++];
		for(int i = bgn[p];i;i = nxt[i]) if(c[i] ^ u[i])
		{
			int v = to[i];
			if(!deep[v])
				deep[v] = deep[p] + 1,q[r++] = v;
		}
	}
	return deep[T];
}
int DFS(int p,int W)
{
	if(!W || p == T) return W;
	int res = 0;
	for(int& i = nbgn[p];i;i = nxt[i]) if(deep[to[i]] == deep[p] + 1)
	{
		int x = DFS(to[i],min(W,c[i] - u[i]));
		res += x,W -= x,u[i] += x,u[i ^ 1] -= x;
		if(!W) break;
	}
	return res;
}
void Flow()
{
	flow = 0;
	for(int i = 2;i <= idx;i++) u[i] = 0;
	while(BFS())
		flow += DFS(S,inf);
}
int val[211];
int n,m,k,s,t;
long long ans;
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin >> n >> m >> k;
	cin >> s >> t;
	S = s,T = t + n;
	usv = 2 * n;
	for(int i = 1;i <= n;i++)
	{
		cin >> val[i];
		add(i,i + n,val[i]);
	}
	while(m--)
	{
		int x,y;
		cin >> x >> y;
		add(x + n,y,inf);
	}
	BFS();
	if(deep[T] == 0)
	{
		cout << 0;
		return 0;
	}
	if(deep[T] < (k << 1))
	{
		cout << -1;
		return 0;
	} 
	while(k--)
	{
		Flow();
		ans += flow;
		for(int i = 1;i <= n;i++) if(deep[i] && !deep[i + n])
			c[i * 2] = inf;
	}
	cout << ans;
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3472kb

input:

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

output:

-1

result:

ok answer = IMPOSSIBLE

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 3532kb

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:

39

result:

wrong answer Integer parameter [name=p; number of vertices] equals to 39, violates the range [-1, 7]