QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#486473#1359. Setting Mapsyqh2025WA 2ms8560kbC++142.4kb2024-07-21 20:26:532024-07-21 20:26:53

Judging History

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

  • [2024-07-21 20:26:53]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:8560kb
  • [2024-07-21 20:26:53]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int inf=1e9;
namespace maxflow{
	const int NS=1e5+10,inf=1e9,MS=1e6+10;
	int s,t;
	struct as{
		int v,w;
	}e[MS];
	int k=-1;
	vector<int>f[NS];
	int now[NS],dep[NS];
	bool bfs(){
		memset(now,0,sizeof(now));
		memset(dep,0,sizeof(dep));
		queue<int>q;q.push(s);dep[s]=1;
		while(!q.empty()){
			int u=q.front();q.pop();
			for(int i=0,fs=f[u].size();i<fs;i++){
				int v=e[f[u][i]].v,w=e[f[u][i]].w;
				if(w&&!dep[v]){
					dep[v]=dep[u]+1;
					if(v==t)return 1;
					q.push(v);
				}
			}
		}
		return 0;
	}
	int dfs(int u,int sum){
		if(u==t)return sum;
		int x,fl=0;
		for(int i=now[u],fs=f[u].size();i<fs&&sum;i++){
			now[u]=i;
			int v=e[f[u][i]].v,w=e[f[u][i]].w;
			if(dep[v]==dep[u]+1&&w){
				x=dfs(v,min(sum,w));
				if(!x)dep[v]=0;
				e[f[u][i]].w-=x;e[f[u][i]^1].w+=x;
				fl+=x,sum-=x;
			}
		}
		return fl;
	}
	void add(int x,int y,int z){
		// cout<<x<<" "<<y<<" "<<z<<endl;
		e[++k]=(as){y,z};f[x].push_back(k);
		e[++k]=(as){x,0};f[y].push_back(k);
	}
	int ZDL(int ss,int tt){
		s=ss,t=tt;int ans=0;
		while(bfs())ans+=dfs(s,inf);
		return ans;
	}
	void init(){
		for(int i=0;i<=k;i++)e[i].w=e[i].v=0;
		k=-1;s=t=0;
		for(int i=0;i<NS;i++)f[i].clear();
		memset(dep,0,sizeof(dep)),memset(now,0,sizeof(now));
	}
}
const int N=1e5+10;
int n,m,k,c[N];
int s,t;
int main(){
	scanf("%d%d%d",&n,&m,&k);
	scanf("%d%d",&s,&t);
	int sum=0;
	for(int i=1;i<=n;i++){
		scanf("%d",&c[i]);sum+=c[i];
		int x=i*2,y=i*2+1;
		for(int j=1;j<=k;j++){
			maxflow::add((x-1)*k+j,(y-1)*k+j,c[i]);
			if(j<k){
				maxflow::add((x-1)*k+j,(y-1)*k+j+1,inf);
				maxflow::add((x-1)*k+j,(x-1)*k+j+1,inf);
				// if(i==n)
				maxflow::add((y-1)*k+j,(y-1)*k+j+1,inf);
			}
		}
	}
	for(int i=1;i<=m;i++){
		int u,v;scanf("%d%d",&u,&v);
		int x=u*2+1,y=v*2;
		for(int j=1;j<=k;j++){
			maxflow::add((x-1)*k+j,(y-1)*k+j,inf);
		}
	}
	s=(s*2-1)*k+1,t=k*(t*2)+k;
	// cout<<s<<" "<<t<<endl;
	int ans=maxflow::ZDL(s,t);
	// cout<<ans<<endl;
	if(ans>sum){
		cout<<-1;return 0;
	}
	maxflow::bfs();
	vector<int>ve;
	for(int i=1;i<=n;i++){
		int x=i*2,y=i*2+1;
		for(int j=1;j<=k;j++){
			if(maxflow::dep[(x-1)*k+j]&&!maxflow::dep[(y-1)*k+j]){
				// cout<<i<<" "<<j<<endl;
				ve.push_back(i);
				break;
			}
		}
	}
	cout<<ve.size()<<endl;
	for(int i:ve)cout<<i<<" ";
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

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

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

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: 2ms
memory: 7372kb

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

input:

2 1 5
1 2
10 10
1 2

output:

-1

result:

ok answer = IMPOSSIBLE

Test #8:

score: 0
Accepted
time: 1ms
memory: 7800kb

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

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: 2ms
memory: 7940kb

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: 2ms
memory: 7292kb

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

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:

2
124 174 

result:

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