【Link】:http://acm.hdu.edu.cn/showproblem.php?pid=1083

【Description】



有p门的课,每门课都有若干学生,现在要为每个课程分配一名课代表,每个学生只能担任一门课的课代表,如果每个课都能找到课代表,则输出”YES”,否则”NO”。

【Solution】



二分图最大匹配.

看看是不是完美匹配即可.



【NumberOf WA】



0



【Reviw】

【Code】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rs(x) scanf("%s",x+1)
#define oi(x) printf("%d",x)
#define ol(x) printf("%lld",x)
#define oc putchar(' ')
#define os(x) printf(x)
#define all(x) x.begin(),x.end()
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 400; int p,n,pre[N+10],Try[N+10];
vector <int> g[N+10]; bool hungary(int x){
int len = g[x].size();
rep1(i,0,len-1){
int y = g[x][i];
if (!Try[y]){
Try[y] = 1;
if (pre[y]==-1 || hungary(pre[y])){
pre[y] = x;
return true;
}
}
}
return false;
} int main(){
//Open();
//Close();
int T;
ri(T);
while (T--){
rep1(i,1,N) g[i].clear();
ri(p),ri(n);
rep1(i,1,p){
int cnt;
ri(cnt);
rep1(j,1,cnt){
int x;
ri(x);
g[x].pb(i + n);
}
}
int ans = 0;
ms(pre,255);
rep1(i,1,n){
ms(Try,0);
if (hungary(i)) ans++;
}
if (ans == p)
puts("YES");
else
puts("NO");
}
return 0;
}

【hdu 1083】Courses的更多相关文章

  1. 【数位dp】【HDU 3555】【HDU 2089】数位DP入门题

    [HDU  3555]原题直通车: 代码: // 31MS 900K 909 B G++ #include<iostream> #include<cstdio> #includ ...

  2. 【HDU 5647】DZY Loves Connecting(树DP)

    pid=5647">[HDU 5647]DZY Loves Connecting(树DP) DZY Loves Connecting Time Limit: 4000/2000 MS ...

  3. -【线性基】【BZOJ 2460】【BZOJ 2115】【HDU 3949】

    [把三道我做过的线性基题目放在一起总结一下,代码都挺简单,主要就是贪心思想和异或的高斯消元] [然后把网上的讲解归纳一下] 1.线性基: 若干数的线性基是一组数a1,a2,a3...an,其中ax的最 ...

  4. 【HDU 2196】 Computer(树的直径)

    [HDU 2196] Computer(树的直径) 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 这题可以用树形DP解决,自然也可以用最直观的方法解 ...

  5. 【HDU 2196】 Computer (树形DP)

    [HDU 2196] Computer 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 刘汝佳<算法竞赛入门经典>P282页留下了这个问题 ...

  6. 【HDU 5145】 NPY and girls(组合+莫队)

    pid=5145">[HDU 5145] NPY and girls(组合+莫队) NPY and girls Time Limit: 8000/4000 MS (Java/Other ...

  7. 【hdu 1043】Eight

    [题目链接]:http://acm.hdu.edu.cn/showproblem.php?pid=1043 [题意] 会给你很多组数据; 让你输出这组数据到目标状态的具体步骤; [题解] 从12345 ...

  8. 【HDU 3068】 最长回文

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=3068 [算法] Manacher算法求最长回文子串 [代码] #include<bits/s ...

  9. 【HDU 4699】 Editor

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=4699 [算法] 维护两个栈,一个栈放光标之前的数,另外一个放光标之后的数 在维护栈的同时求最大前缀 ...

随机推荐

  1. IDEA中如何设置自动导包

    IDEA跟eclipse还是有一些差别,一些东西要自己去设置,但同时也还是有快捷键的方式来帮助我们 1.如何设置自动导包:如下图所示 点击FIle--->settings 其次还可以通过按快捷键 ...

  2. vue2.0-transition多个元素

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. .net framework tools

    https://docs.microsoft.com/en-us/dotnet/framework/tools/ Resgen.exe (Resource File Generator) Conver ...

  4. SOAPUI使用

    简介:在开发接口的时候每次验证接口是否正确都需要手动写测试DEMO来验证,使用SOAPUI可以大大减少测试时间. 目录 1.SOPUI介绍... 1 2.SOAPUI使用... 1 2.1新建SOAP ...

  5. POJ 1895 分层图网络流+输出路径

    题意: 题目描述:在公元3141年人类的足迹已经遍布银河系.为了穿越那巨大的距离,人类发明了一种名为超时空轨道的技术.超时空轨道是双向的,连接两个星系,穿越轨道需要一天的时间.然而这个轨道只能同时给一 ...

  6. MySQL Server 5.5.44免安装版配置详解

    转载地址:http://wenku.baidu.com/view/2a8bfe6a25c52cc58bd6beff.html### 一 下载MySQL http://dev.mysql.com/dow ...

  7. python code 1_username registration & login

    This tiny program consists of 2 parts - registration and login. In the part of registration, the key ...

  8. 【转】python的zipfile压缩、解压缩

    网上搜索了很多关于python的zipfile压缩.解压缩.觉得讲述比较详细,例子也很明了.由于比较懒,就直接复制了. 以下内容大部分转于 http://blog.csdn.net/jgood/art ...

  9. RQNOJ PID496/[IOI1999]花店橱窗布置

    PID496 / [IOI1999]花店橱窗布置 ☆   题目描述 某花店现有F束花,每一束花的品种都不一样,同时至少有同样数量的花瓶,被按顺序摆成一行,花瓶的位置是固定的,从左到右按1到V顺序 编号 ...

  10. [Python] Working with file

    Python allows you to open a file, do operations on it, and automatically close it afterwards using w ...