QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#491413 | #8759. 小班课 | XiaoShanYunPan | WA | 0ms | 3812kb | C++14 | 1.6kb | 2024-07-25 19:21:14 | 2024-07-25 19:21:15 |
Judging History
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