QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#282265#1359. Setting MapszhichengWA 1ms7916kbC++142.1kb2023-12-11 17:06:372023-12-11 17:06:37

Judging History

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

  • [2023-12-11 17:06:37]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7916kb
  • [2023-12-11 17:06:37]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1010,M=200010;
int tot=1,minu,maxu,vis[N],cur[N],lev[N],src,des,first[N],nnext[M],to[M];
ll w[M],ww[M];
queue<int>q;
vector<int>anss;
void add(int x,int y,ll z){
	nnext[++tot]=first[x];
	first[x]=tot;
	to[tot]=y;
	w[tot]=z;
}
bool bfs(){
	int u;
	while(!q.empty()){
		q.pop();
	}
	for(int i=minu;i<=maxu;i++){
		cur[i]=first[i];
		lev[i]=-1;
	}
	lev[src]=0;
	q.push(src);
	while(!q.empty()){
		u=q.front();
		q.pop();
		for(int e=first[u];e;e=nnext[e]){
			if(w[e]&&lev[to[e]]==-1){
				lev[to[e]]=lev[u]+1;
				q.push(to[e]);
				if(to[e]==des){
					return 1;
				}
			}
		}
	}
	return 0;
}
ll dinic(int u,ll flow){
	ll res=0,delta;
	if(u==des){
		return flow;
	}
	for(int &e=cur[u];e;e=nnext[e]){
		if(w[e]&&lev[to[e]]>lev[u]){
			delta=dinic(to[e],min(flow-res,w[e]));
			if(delta){
				w[e]-=delta;
				w[e^1]+=delta;
				res+=delta;
				if(flow==res){
					break;
				}
			}
		}
	}
	if(flow!=res){
		lev[u]=-1;
	}
	return res;
}
void dfs(int u){
	vis[u]=1;
	for(int e=first[u];e;e=nnext[e]){
		if(!vis[to[e]]&&w[e]>0){
			dfs(to[e]);
		}
	}
}
int main(){
	int n,m,k,a,b,pp=0;
	ll ans=0;
	scanf("%d%d%d%d%d",&n,&m,&k,&src,&des);
	minu=1;
	maxu=n*2*k;
	des+=(k-1)*n*2+n;
	for(int i=1;i<=n;i++){
		scanf("%d",&a);
		for(int j=1;j<=k;j++){
			add((j-1)*2*n+i,(j-1)*2*n+i+n,a);
			add((j-1)*2*n+i+n,(j-1)*2*n+i,0);
		}
	}
	while(m--){
		scanf("%d%d",&a,&b);
		for(int i=1;i<=k;i++){
			add((i-1)*2*n+a+n,(i-1)*2*n+b,1e18);
			add((i-1)*2*n+b,(i-1)*2*n+a+n,0);
		}
	}
	for(int i=1;i<=k-1;i++){
		for(int j=1;j<=n;j++){
			add((i-1)*2*n+j,i*2*n+j+n,1e18);
			add(i*2*n+j+n,(i-1)*2*n+j,0);
		}
	}
	while(bfs()){
		ans+=dinic(src,1e18);
		pp=1;
	}
	if(!pp){
		printf("-1");
		return 0;
	}
	dfs(src);
	for(int i=1;i<=n*2*k;i++){
		for(int e=first[i];e;e=nnext[e]){
			if(vis[i]&&!vis[to[e]]&&to[e]==i+n&&w[e]==0){
				anss.push_back(i%(n*2));
			}
		}
	}
	printf("%d\n",anss.size());
	for(auto i:anss){
		printf("%d ",i);
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 1ms
memory: 5876kb

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: 1ms
memory: 5884kb

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: 1ms
memory: 6132kb

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: 1ms
memory: 5956kb

input:

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

output:

5
1 2 3 4 5 

result:

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