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 赤裸裸的二分匹配大水题的更多相关文章
- ZOJ 1654 二分匹配基础题
题意: 给你一副图, 有草地(*),空地(o)和墙(#),空地上可以放机器人, 机器人向上下左右4个方向开枪(枪不能穿墙),问你在所有机器人都不相互攻击的情况下能放的最多的机器人数. 思路:这是一类经 ...
- UVALive 6525 Attacking rooks 二分匹配 经典题
题目链接:option=com_onlinejudge&Itemid=8&page=show_problem&problem=4536">点击打开链接 题意: ...
- POJ 1469 ZOJ1140 二分匹配裸题
很裸,左点阵n,右点阵m 问最大匹配是否为n #include <cstdio> #include <cstring> #include <vector> usin ...
- Machine Schedule 赤裸裸的二分匹配 二部图中的点覆盖书==匹配数
Machine Schedule 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 ...
- UVA5874 Social Holidaying 二分匹配
二分匹配简单题,看懂题意,建图比较重要. #include<stdio.h> #include<string.h> #define maxn 1100 int map[maxn ...
- hdu 1068 Girls and Boys (二分匹配)
Girls and Boys Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- poj2239 poj1274【二分匹配】
题意: 就是尽可能的选多的课 思路: 把课程和上课的时间看作二分图 跑一跑二分匹配就好了 #include<iostream> #include<cstdio> #includ ...
- POJ-1274The Perfect Stall,二分匹配裸模板题
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 23313 Accepted: 103 ...
- POJ 1466 Girls and Boys 黑白染色 + 二分匹配 (最大独立集) 好题
有n个人, 其中有男生和女生,接着有n行,分别给出了每一个人暗恋的对象(不止暗恋一个) 现在要从这n个人中找出一个最大集合,满足这个集合中的任意2个人,都没有暗恋这种关系. 输出集合的元素个数. 刚开 ...
随机推荐
- mysql基础之mysql主从架构半同步复制
一.概念 1.异步复制(Asynchronous replication) MySQL默认的复制即是异步的,主库在执行完客户端提交的事务后会立即将结果返给给客户端,并不关心从库是否已经接收并处理,这样 ...
- Redis 安装和启动
Redis 安装 安装准备: redis 压缩包 官网下载地址:https://redis.io/download 安装步骤: 第一步:安装 gcc 编译器 官网发布的 Redis 压缩包是 C 语言 ...
- Lua中的基本函数库--(转自忧郁的加菲猫)
基本函数库为Lua内置的函数库,不需要额外装载assert (v [, message])功能:相当于C的断言,参数:v:当表达式v为nil或false将触发错误,message:发生错误时返回的信息 ...
- S6 文件备份与压缩命令
6.1 tar:打包备份 6.2 gzip:压缩或解压文件 6.3-4 zip.unzip 6.5 scp:远程文件复制 6.6 rsync:文件同步工具
- centos 7修改yum源
centos系统要定期更新,前天使用sudo yum update命令更新过程中出错,安装的是x64的系统,结果更新的内容有i686的依赖包,最终由于64与32位系统依赖的原因导致更新失败,更糟糕的是 ...
- 我的Python书被台湾的出版社引进版权了,书的名字也更吸引人了
我去年出了一本Python书,基于股票大数据分析的Python入门实战,在这本书里,我是用股票范例讲述Pythorn的爬虫,数据分析和机器学习知识点,如下是京东的连接. https://item.jd ...
- 西门子 S7300 以太网模块连接组态王方法
北京华科远创科技有限研发的远创智控ETH-YC模块,以太网通讯模块型号有MPI-ETH-YC01和PPI-ETH-YC01,适用于西门子S7-200/S7-300/S7-400.SMART S7-20 ...
- php代码审计之命令执行中windows/linux的差异化问题
昨天好基友发来了一段代码,还是挺有趣的,记录下: <?php $a = '\''.str_replace("'","\'",$_GET[1]).'\''; ...
- eclispe--tomcat配置
eclipse安装tomcat方法: 1.下载tomcat,从官网下载,地址:http://tomcat.apache.org/download-70.cgi 2.将下载下来的压缩包解压,放在自己想放 ...
- 微服务架构(Microservices) ——Martin Flower
不知不觉到达了Sring Boot的学习中了,在学习之前,了解微服务架构是很有必要的,对于自己提升今后面试的软实力有很大帮助,在此写下. 让我们接下来看下Martin Flower 如何解释微服务架构 ...