QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#491413#8759. 小班课XiaoShanYunPanWA 0ms3812kbC++141.6kb2024-07-25 19:21:142024-07-25 19:21:15

Judging History

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

  • [2024-07-25 19:21:15]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3812kb
  • [2024-07-25 19:21:14]
  • 提交

answer

/*
结论:答案就是最大匹配
*/
#include<bits/stdc++.h>
using namespace std;
constexpr int N=1010,INF=0x7fffffff;
int cnt=1,first[N];
struct Edge{
	int u,v,w,nex;
}a[N*N];
void add(int u,int v,int w){
	//printf("%d %d %d\n",u,v,w);
	a[++cnt]={u,v,w,first[u]};
	first[u]=cnt;
	a[++cnt]={v,u,0,first[v]};
	first[v]=cnt;
}
int s,t,dep[N];
queue<int>q;
bool bfs(int s){
	memset(dep,-1,sizeof dep);
	dep[s]=0;
	q.push(s);
	while(!q.empty()){
		int u=q.front();q.pop();
		for(int i=first[u];i;i=a[i].nex){
			int v=a[i].v,w=a[i].w;
			if(!~dep[v]&&w>0){
				dep[v]=dep[u]+1;
				q.push(v);
			}
		}
	}
	return ~dep[t];
}
int head[N];
int dfs(int u,int flow){
	if(u==t)return flow;
	int sur=flow;
	for(int i=head[u];i&&sur;i=a[i].nex){
		head[u]=i;
		int v=a[i].v,w=a[i].w;
		if(dep[v]==dep[u]+1&&w){
			int x=dfs(v,min(sur,w));
			sur-=x;
			a[i].w-=x;
			a[i^1].w+=x;
		}
	}
	return flow-sur;
}
int dinic(int s){
	int res=0;
	while(bfs(s)){
		memcpy(head,first,sizeof head);
		res+=dfs(s,INF);
	}
	return res;
}
int n,m,i,x,j,k;
void work(){
	cnt=1;
	memset(first,0,sizeof first);
	scanf("%d%d",&n,&m);
	for(i=1;i<=m;++i)scanf("%d",&x),add(n+i,t,x);
	for(i=1;i<=n;++i){
		scanf("%d",&k);
		add(s,i,1);
		for(j=1;j<=k;++j)scanf("%d",&x),add(i,n+x,1);
	}
	printf("%d\n",dinic(s));
	for(i=1;i<=n;++i){
		for(j=first[i];j;j=a[j].nex){
			int v=a[j].v,w=a[j].w;
			if(!w){
				printf("%d ",v-n);
				break;
			}
		}
	}
	putchar(10);
}
int T;
int main(){
	s=N-5,t=s+1;
	scanf("%d",&T);
	while(T--)work();
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3812kb

input:

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

output:

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

result:

wrong answer not a permutation