hdu1083

#include"stdio.h"
#include"string.h"
#define N 305
int mark[N],link[N],map[N][N],p;
int find(int a) //匈牙利算法,二分匹配
{
int i;
for(i=1;i<=p;i++)
{
if(!mark[i]&&map[a][i])
{
mark[i]=1;
if(!link[i]||find(link[i]))//若i已经配对,则查找和i配对的
{ //那个元素是否还能和其他元素配对
link[i]=a;
return 1;
}
}
}
return 0;
}
int main()
{
int t,n,i,a,m,ans;
scanf("%d",&t);
while(t--)
{
memset(link,0,sizeof(link));
memset(map,0,sizeof(map));
scanf("%d%d",&p,&n);
for(i=1;i<=p;i++)
{
scanf("%d",&m);
while(m--)
{
scanf("%d",&a);
map[a][i]=1;
}
}
ans=0;
for(i=1;i<=n;i++)
{
memset(mark,0,sizeof(mark));
ans+=find(i);
}
if(ans==p) //最大匹配数等于课程数
printf("YES\n");
else
printf("NO\n");
}
return 0;
}

时间: 2024-12-24 05:45:28

hdu1083的相关文章

hdu2063+hdu1083(最大匹配数)

传送门:hdu2063过山车 #include <cstdio> #include <cstring> #include <string> #include <cmath> #include <iostream> #include <algorithm> #include <queue> #include <cstdlib> #include <stack> #include <vector&

HDU1083 Courses —— 二分图最大匹配

题目链接:https://vjudge.net/problem/HDU-1083 Courses Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 8869    Accepted Submission(s): 4319 Problem Description Consider a group of N students and P c

HDU1083(最大匹配)

Courses Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5414    Accepted Submission(s): 2600 Problem Description Consider a group of N students and P courses. Each student visits zero, one or

二分图的最大匹配(匈牙利算法)HDU1083

二分图: 二分图又称作二部图,是图论中的一种特殊模型. 设G=(V,E)是一个无向图,如果顶点V可分割为两个互不相交的子集(A,B),并且图中的每条边(i,j)所关联的两个顶点i和j分别属于这两个不同的顶点集(i in A,j in B),则称图G为一个二分图. 无向图G为二分图的充分必要条件是,G至少有两个顶点,且其所有回路的长度均为偶数. 最大匹配: 给定一个二分图G,在G的一个子图M中,M的边集中的任意两条边都不依附于同一个顶点,则称M是一个匹配. 选择这样的边数最大的子集称为图的最大匹配

poj 1469 (hdu1083)COURSES 最大匹配

COURSES Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 17153   Accepted: 6740 Description Consider a group of N students and P courses. Each student visits zero, one or more than one courses. Your task is to determine whether it is poss

HDU1083(KB10-C 二分图最大匹配)

Courses Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 8490    Accepted Submission(s): 4134 Problem Description Consider a group of N students and P courses. Each student visits zero, one or

HDU1083 :Courses(二分图匹配)

Cources Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 11298    Accepted Submission(s): 5299 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1083 Description: Consider a group of N students an

HDU-1083-Courses(最大匹配)

链接: https://vjudge.net/problem/HDU-1083#author=HUCM201732 题意: 题目大意: 一共有N个学生跟P门课程,一个学生可以任意选一 门或多门课,问是否达成: 1.每个学生选的都是不同的课(即不能有两个学生选同一门课) 2.每门课都有一个代表(即P门课都被成功选过) 输入为: 第一行一个T代表T组数据 P N(P课程数, N学生数) 接着P行: 第几行代表第几门课程,首先是一个数字k代表对这门课程感兴趣的同学的个数,接下来是k个对这门课程感兴趣同