COURSES

 1 #include <iostream>
2 #include <cstdio>
3 #include <cstring>
4 #include <cmath>
5 #include <algorithm>
6 #include <string>
7 #include <vector>
8 #include <set>
9 #include <map>
10 #include <stack>
11 #include <queue>
12 #include <sstream>
13 #include <iomanip>
14 using namespace std;
15 typedef long long LL;
16 const int INF = 0x4fffffff;
17 const double EXP = 1e-5;
18 const int MS = 305;
19 const int SIZE = 100005;
20
21 // data struct
22 int n,m;
23 int edges[MS][MS];
24 int cx[MS],cy[MS];
25 int mark[MS];
26
27 int path(int u)
28 {
29 for(int v=1;v<=m;v++)
30 {
31 if(edges[u][v]&&!mark[v])
32 {
33 mark[v]=1;
34 if(cy[v]==-1||path(cy[v]))
35 {
36 cx[u]=v; // 可以不要cx
37 cy[v]=u;
38 return 1;
39 }
40 }
41 }
42 return 0;
43 }
44
45 void match()
46 {
47 int ans=0;
48 memset(cx,0xff,sizeof(cx));
49 memset(cy,0xff,sizeof(cy));
50 for(int u=1;u<=n;u++)
51 {
52 if(cx[u]==-1)
53 {
54 memset(mark,0,sizeof(mark));
55 ans+=path(u);
56 }
57 }
58 if(ans==n)
59 printf("YES\n");
60 else
61 printf("NO\n");
62 }
63
64 int main()
65 {
66 int T,u,v;
67 scanf("%d",&T);
68 while(T--)
69 {
70 scanf("%d%d",&n,&m);
71 memset(edges,0,sizeof(edges));
72 int cnt;
73 for( u=1;u<=n;u++)
74 {
75 scanf("%d",&cnt);
76 for(int i=1;i<=cnt;i++)
77 {
78 scanf("%d",&v);
79 edges[u][v]=1;
80 }
81 }
82 match();
83
84 }
85 return 0;
86 }

COURSES 赤裸裸的二分匹配大水题的更多相关文章

  1. ZOJ 1654 二分匹配基础题

    题意: 给你一副图, 有草地(*),空地(o)和墙(#),空地上可以放机器人, 机器人向上下左右4个方向开枪(枪不能穿墙),问你在所有机器人都不相互攻击的情况下能放的最多的机器人数. 思路:这是一类经 ...

  2. UVALive 6525 Attacking rooks 二分匹配 经典题

    题目链接:option=com_onlinejudge&Itemid=8&page=show_problem&problem=4536">点击打开链接 题意: ...

  3. POJ 1469 ZOJ1140 二分匹配裸题

    很裸,左点阵n,右点阵m 问最大匹配是否为n #include <cstdio> #include <cstring> #include <vector> usin ...

  4. Machine Schedule 赤裸裸的二分匹配 二部图中的点覆盖书==匹配数

    Machine Schedule 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 ...

  5. UVA5874 Social Holidaying 二分匹配

    二分匹配简单题,看懂题意,建图比较重要. #include<stdio.h> #include<string.h> #define maxn 1100 int map[maxn ...

  6. hdu 1068 Girls and Boys (二分匹配)

    Girls and Boys Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  7. poj2239 poj1274【二分匹配】

    题意: 就是尽可能的选多的课 思路: 把课程和上课的时间看作二分图 跑一跑二分匹配就好了 #include<iostream> #include<cstdio> #includ ...

  8. POJ-1274The Perfect Stall,二分匹配裸模板题

    The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 23313   Accepted: 103 ...

  9. POJ 1466 Girls and Boys 黑白染色 + 二分匹配 (最大独立集) 好题

    有n个人, 其中有男生和女生,接着有n行,分别给出了每一个人暗恋的对象(不止暗恋一个) 现在要从这n个人中找出一个最大集合,满足这个集合中的任意2个人,都没有暗恋这种关系. 输出集合的元素个数. 刚开 ...

随机推荐

  1. pgrep cron

    # pgrep cron947[root@localhost cron]# pgrep --help Usage: pgrep [options] <pattern> Options: - ...

  2. 11.13 ethtool:查询网卡参数

    ethtool命令用于查询或设置网卡参数. ethtool [devname] [root@linuxprobe ~]# ethtool eth0 Settings for eth0:  Suppor ...

  3. 7.1 useradd:创建用户

    7.1 useradd:创建用户 1 使用useradd 常规添加用户工作原理流程     在使用useradd命令时,若不加任何参数选项,后面直接跟所添加的用户名,那么系统首先会读取/etc/log ...

  4. 9.4-6 kill & killall & pkill

    kill:终止进程 能够终止你希望停止的进程. kill 命令的参数选项及说明 -l    列出全部的信号名称 -p    指定kill命令只打印相关进程的进程号,而不发送任何信号 -s    指定要 ...

  5. python3 xlrd包的用法

    一.xlrd的安装 pip install xlrd 二.xlrd使用介绍 1.导入模块 import xlrd 2.打开Excel文件,实例化为readbook readbook = xlrd.op ...

  6. GNU Linux启动时文件系统mountall挂载出错问题的处理

    /********************************************************************* * Author  : Samson * Date    ...

  7. 多条件分页 (Day_31)

    接我的上篇博客  EasyUI_使用datagrid分页 (Day_28) . 按惯例,我们先看效果图 EasyUI 实现多条件分页很简单. 我们先来通过官网了解下这两个属性: 显然,有了load 方 ...

  8. Django 自定义表名和字段名

    Django 自定义表名和字段名 通过db_table和db_column自定义数据表名和字段名 假如你的数据库里已经有了一张数据表,且该表包含多个字段,你希望通过Django直接访问该数据表的各个字 ...

  9. Win7 64 + mysql5.6.24(.zip) 不知道root密码的情况下重设密码

    解决方式 第一步:在运行(常常在附件中)里输出cmd,右键以系统管理员身份登陆: 第二步:停止mysql服务,命令为:net stop mysql  注意,若不行将当前目录切换到mysql\bin目录 ...

  10. 201871030132-熊文婷 实验二 个人项目―《D{0-1}KP问题》项目报告

    项目 内容 课程班级博客链接 https://edu.cnblogs.com/campus/xbsf/2018CST 这个作业要求链接 https://www.cnblogs.com/nwnu-dai ...