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. Python检查 文件备份是否正常 云备份进程是否正常运行

    场景:服务器自动备份数据库文件,每两小时生成一个新备份文件,通过云备份客户端自动上传,需要每天检查是否备份成功. 实现:本脚本实现检查文件是否备份成功,进程是否正常运行,并且发送相关邮件提醒. #! ...

  2. 创建第一个django工程

    一.环境搭建 使用anaconda + pycharm的环境. 1.创建虚拟环境并安装django1.8的包 # 创建虚拟环境 conda create -n django python=3.6 # ...

  3. IDEA 安装 zookeeper 可视化管理插件

    1. 安装 zookeeper 插件 打开 IDEA->Settings->Plugins,然后在 Marketplace 输入 "zookeeper" 如下: 插件安 ...

  4. mysql3_pymysql

    python数据库编程 1.pyshon数据库接口(python DB-API) 1.为开发人员提供的数据库应用编程接口 2.python支持的数据库服务软件 mysql,oracle,sql_ser ...

  5. python3 读取txt文件数据,绘制趋势图,matplotlib模块

    python3 读取txt文件数据,绘制趋势图 test1.txt内容如下: 时间/min cpu使用率/% 内存使用率/% 01/12-17:06 0.01 7.61 01/12-17:07 0.0 ...

  6. 3.1 cat:合并文件或查看文件内容

    cat 命令 可以理解为英文单词concatenate的缩写,其功能是连接多个文件并且打印到屏幕输出,或者重定向到指定的文件中.此命令常用来显示单个文件内容,或者将几个文件内容连接起来一起显示,还可以 ...

  7. redis 基本操作命令

    redis 基本操作 String 操作字符串 1 SET key value 设置指定 key 的值 ​ 2 GET key 获取指定 key 的值. ​ 3 GETRANGE key start ...

  8. Django(37)配置django日志

    前言   django框架的日志通过python内置的logging模块实现的,既可以记录自定义的一些信息描述,也可以记录系统运行中的一些对象数据,还可以记录包括堆栈跟踪.错误代码之类的详细信息.   ...

  9. IDEA中怎么创建ini文件

    首先博主在这使用的是idea的2019.3.2的版本,不知道的话可以打开help菜单的about查看 第一步: 具体需要在setings安装ini插件 第二步: 在File Types中查看ini,没 ...

  10. go语言json技巧

    go语言json技巧 本文总结了在项目中遇到的那些关于go语言JSON数据与结构体之间相互转换的问题及解决办法. 基本的序列化 首先我们来看一下Go语言中json.Marshal()(系列化)与jso ...