QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#80435#1359. Setting MapsXZTmaxsmall67WA 2ms3560kbC++231.5kb2023-02-23 18:10:282023-02-23 18:10:31

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-23 18:10:31]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3560kb
  • [2023-02-23 18:10:28]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=2005,M=2e5+5,inf=2e9+7;
struct edge{
	int to,nxt,f;
}e[M];
int n,m,k,s,t,ct=1,hd[N],cur[N],dep[N],b[205][5][2],S,T,maxf;
void add(int u,int v,int f){
	e[++ct]=(edge){v,hd[u],f};hd[u]=ct;
	e[++ct]=(edge){u,hd[v],0};hd[v]=ct;
}
inline bool bfs(){
	queue<int> q;
	memcpy(cur,hd,(t+1)<<2);
	memset(dep,0,(t+1)<<2);
	dep[s]=1;q.push(s);
	while(!q.empty()){
		int u=q.front();q.pop();
		for(int i=hd[u],v;i;i=e[i].nxt){
			v=e[i].to;
			if(!dep[v]&&e[i].f>0) dep[v]=dep[u]+1,q.push(v);
		}
	}
	return dep[t];
}
int dfs(int u,int li){
	if(u==t) return li;
	int f1=0,tp;
	for(int i=cur[u],v;i;i=e[i].nxt){
		v=e[i].to;cur[u]=i;
		if(dep[v]==dep[u]+1&&e[i].f>0){
			tp=dfs(v,min(li,e[i].f));	
			f1+=tp;li-=tp;
			e[i].f-=tp;e[i^1].f+=tp;
			if(!li) break;
		}
	}
	if(!f1) dep[u]=0;
	return f1;
}
vector<int> cs;
int main(){
	cin>>n>>m>>k>>S>>T;
	for(int i=1,w;i<=n;i++){
		scanf("%d",&w);
		for(int j=0;j<k;j++){
			b[i][j][0]=++t;b[i][j][1]=++t;
			add(t-1,t,w);
			if(j) add(b[i][j-1][0],t,inf);
		}
	}
	t++;add(s,b[S][0][0],inf);
	for(int i=1,u,v;i<=m;i++){
		scanf("%d%d",&u,&v);
		for(int j=0;j<k;j++) add(b[u][j][1],b[v][j][0],inf);
	}
	 add(b[T][k-1][1],t,inf);
	while(bfs()) maxf+=dfs(s,inf);
	if(maxf>=inf) puts("-1"),exit(0);
	for(int i=1;i<=n;i++) for(int j=0;j<k;j++)
		if(dep[b[i][j][0]]&&!dep[b[i][j][1]]){cs.push_back(i);break;}
	printf("%d\n",(int)cs.size());
	for(int u:cs) printf("%d ",u);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 3560kb

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