📄 1083.cpp
字号:
#include<stdio.h>
#include<string.h>
bool cour_stu[120][310],flag[310];
int match[310];
int p,n,num;
bool dfs(int i){
for(int j=0;j<n;j++)
if(cour_stu[i][j]&&!flag[j]){
flag[j]=1;
if(match[j]==-1||dfs(match[j])){
match[j]=i;
return true;
}
}
return false;
}
void binary_match(){
memset(match,-1,sizeof(match));
for(int i=0;i<p;i++){
memset(flag,0,sizeof(flag));
if(dfs(i))
num++;
}
}
int main()
{
int i,j,ntest,s,t;
scanf("%d",&ntest);
while(ntest--){
scanf("%d %d",&p,&n);
memset(cour_stu,0,sizeof(cour_stu));
for(i=0;i<p;i++){
scanf("%d",&s);
for(j=0;j<s;j++){
scanf("%d",&t);
cour_stu[i][t-1]=1;
}
}
num=0;
binary_match();
if(num==p)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -