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. 马哥Linux SysAdmin学习笔记(一)

    Linux入门 Linux系统管理: 磁盘管理,文件系统管理 RAID基础原理,LVM2 网络管理:TCP/IP协议,Linux网络属性配置 程序包管理:rpm,yum 进程管理:htop,glanc ...

  2. Ansible_利用系统角色重用内容

    一.红帽企业Linux系统角色 1.RHEL系统角色 名称 状态 角色描述 rhel-system-roles.kdump 全面支持 配置kdump崩溃恢复服务 rhel-system-roles.n ...

  3. C语言程序设计#成绩查询系统

    学生成绩管理系统 [注释]:请点赞,好人一生平[yi]安[wo]. #codeblocks程序下编写 #include<stdio.h>#include<stdlib.h>// ...

  4. 10.21 nmap:网络探测工具和安全/端口扫描器

    nmap命令 是一款开放源代码的网络探测和安全审核工具,是Network Mapper的缩写.其设计目标是快速地扫描大型网络.nmap可以发现网络上有哪些主机,主机提供了什么服务(应用程序名称和版本号 ...

  5. Spring5.0源码学习系列之事务管理概述

    Spring5.0源码学习系列之事务管理概述(十一),在学习事务管理的源码之前,需要对事务的基本理论比较熟悉,所以本章节会对事务管理的基本理论进行描述 1.什么是事务? 事务就是一组原子性的SQL操作 ...

  6. Redis学习笔记七:主从集群

    单机,单节点,单实例的Redis会有什么问题呢? 容易导致单点故障,那么如何解决呢? 可以通过主备方式 同时可以实现读写分离 这里的每个节点是全量的,镜像的. 单节点的容量有限而且单点的压力比较大,如 ...

  7. Kubernetes-3.3:ETCD集群搭建及使用(https认证+数据备份恢复)

    etcd集群搭建 环境介绍 基于CentOS Linux release 7.9.2009 (Core) ip hostname role 172.17.0.4 cd782d0a790b etcd1 ...

  8. 用virtualenv建立Python独立开发环境

    1.用pip安装virtualenv sudo apt-get install python-virtualenv 2.1 创建python2的虚拟环境,进入要创建虚拟环境的目录下,我是放在/home ...

  9. Step By Step(Lua数据持久化)

    Step By Step(Lua数据持久化) 1. 数据文件:    我们可以利用Lua中table的构造式来定义一种文件格式,即文件中的数据是table构造并初始化的代码,这种方式对于Lua程序而言 ...

  10. c++ 各种数据结构的时间空间复杂度

    普通线段树    时间 log2(n); 空间 n+log2(n)+log4(n)+log(8)n+.....+logn(n)==n*4; 动态开点线段树 时间 log2(n); 空间 q*log2( ...