QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#516328#1359. Setting MapsczcWA 0ms4012kbC++231.9kb2024-08-12 16:07:512024-08-12 16:07:52

Judging History

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

  • [2024-08-12 16:07:52]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:4012kb
  • [2024-08-12 16:07:51]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int maxn=2005; 
struct edge{
	int to,w,nex;
}e[maxn*50];
int tot=-1;
int head[maxn],now[maxn],d[maxn];
int s,t;
inline void add(int x,int y,int w){
	e[++tot].to=y,e[tot].w=w,e[tot].nex=head[x],head[x]=tot;
	e[++tot].to=x,e[tot].w=0,e[tot].nex=head[y],head[y]=tot;
}
inline bool bfs(){
	memset(now,-1,sizeof(now));
	memset(d,0,sizeof(d));
	queue<int> q;
	d[s]=1,now[s]=head[s];
	q.push(s);
	while(!q.empty()){
		int x=q.front();
		q.pop(); 
		for(int i=head[x];~i;i=e[i].nex){
			int y=e[i].to;
			if(e[i].w && !d[y]){
				d[y]=d[x]+1;
				now[y]=head[y];
				q.push(y);
				if(y==t) return 1;
			}
		}
	}
	return 0;
}
const int INF=1e9;
inline int dinic(int x,int flow){
	if(x==t) return flow;
	int rest=flow;
	for(int i=now[x];~i && rest;i=e[i].nex){
		now[x]=i;
		int y=e[i].to;
		if(e[i].w && d[y]==d[x]+1){
			int k=dinic(y,min(e[i].w,rest));
			e[i].w-=k,e[i^1].w+=k,rest-=k;
		}
	}
	return flow-rest;
}
int n,m,k;
int st,ed;
int main(){
	memset(head,-1,sizeof(head));
	scanf("%d%d%d",&n,&m,&k);
	scanf("%d%d",&st,&ed);
	for(int i=1,c;i<=n;i++){
		scanf("%d",&c);
		int x=i*2-1,y=i*2;
		for(int j=1;j<=k;j++){
			add((x-1)*k+j,(y-1)*k+j,c);
			if(j<k) add((x-1)*k+j,(y-1)*k+j+1,INF);
		}
		if(i==ed){
			for(int j=1;j<k;j++) add((y-1)*k+j,(y-1)*k+j+1,INF);
		}
	}
	for(int i=1,x,y;i<=m;i++){
		scanf("%d%d",&x,&y);
		x=x*2,y=y*2-1;
		for(int j=1;j<=k;j++) add((x-1)*k+j,(y-1)*k+j,INF);
	}
	s=(st*2-2)*k+1,t=(ed*2-1)*k+k;
	int ans=0,flow=0;
	while(bfs()) while((flow=dinic(s,INF))) ans+=flow;
	if(ans>=INF){
		puts("-1");
		return 0;
	}
	vector<int> czc;
	for(int i=1;i<=n;i++){
		int x=i*2-1,y=i*2; 
		for(int j=1;j<=k;j++){
			if(d[(x-1)*k+j] && !d[(y-1)*k+j]){
				czc.push_back(i);
				break;
			}
		}
	}
	printf("%d\n",(int)czc.size());
	for(auto x:czc) printf("%d ",x); 
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

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

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

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

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

input:

2 1 5
1 2
10 10
1 2

output:

-1

result:

ok answer = IMPOSSIBLE

Test #8:

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

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

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

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

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: 0ms
memory: 3736kb

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