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 PATH环境变量及作用(初学者必读)

    Linux PATH环境变量及作用(初学者必读) < 什么是环境变量,Linux环境变量有哪些?Linux打包(归档)和压缩 > <Linux就该这么学>是一本基于最新Linu ...

  2. JLINK下载出现问题

    JLINK 下载报错: RAM CHECK FAILED 说法一: 有一种说法是版本的问题 http://tieba.baidu.com/p/1902940329?red_tag=d180765763 ...

  3. Ubuntu 16.04搭建php5.6 Web服务器环境

    Ubuntu 16.04默认安装php7.0环境,但是php7目前兼容性并不是很好,如果自行安装php5需要清除php7的已安装包,否则会报错. 移除默认及已安装的PHP包 sudo dpkg -l ...

  4. Go语言的函数02---参数

    package main import "fmt" /* 常量,变量,函数---源代码的成员 给成员命名的字符称之为[标识符] 合法的标识符有:大小写字母,数字,下划线 命名时不能 ...

  5. 【注意力机制】Attention Augmented Convolutional Networks

    注意力机制之Attention Augmented Convolutional Networks 原始链接:https://www.yuque.com/lart/papers/aaconv 核心内容 ...

  6. Springboot单元测试@RunWith注解

    1.RunWith 注解 RunWith 就是一个运行器 可以在单元测试的时候,自动创建spring的应用上下文 2.正确使用 pom.xml <dependency> <group ...

  7. springboot中引入zookeeper,生成 配置类

    1.application.properties zookeeper.address=@mvn.zookeeper.address@ zookeeper.namespace=@mvn.zookeepe ...

  8. Torchvision模型微调

    Torchvision模型微调 本文将深入探讨如何对 torchvision 模型进行微调和特征提取,所有这些模型都已经预先在1000类的magenet数据集上训练完成.将深入介绍如何使用几个现代的C ...

  9. Java真的是白天鹅

    前言 我最近越来越真切的感受到,Java真的是白天鹅. 这真的是一种羡慕嫉妒恨的感受. 今天和一个Java技术Leader聊天,我告诉他敏捷开发是以人为本,他居然跟我说敏捷开发在行业内有规范,规范是死 ...

  10. 提高GUI自动化测试稳定性解决方案

    针对"GUI自动化测试稳定性问题"这个问题,最典型的情景就是:同样的测试用例,在同样的测试执行环境下,测试的结果有时是Success,有时是Fail,这严重降低了GUI测试的可信度 ...