题意:N个学生,P个课程,问能不能找到课程的P个匹配。

思路:【早上睡醒了再写】

代码:

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
const int maxn = ;
int n, p;
vector<int> g[maxn];
int from[maxn], tot;
bool use[maxn]; bool match(int x)
{
for (int i = ; i < g[x].size(); i ++) {
if(!use[g[x][i]]) {
use[g[x][i]] = true;
if(from[g[x][i]] == - || match(from[g[x][i]])) {
from[g[x][i]] = x;
return true;
}
}
}
return false;
} int hungary()
{
tot = ;
memset(from, -, sizeof(from));
for(int i = ; i <= n; i ++) {
memset(use, , sizeof(use));
if(match(i)) tot ++;
}
return tot;
} int main()
{
int t; cin>>t;
while(t--) {
for(int i = ; i < maxn; i++) g[i].clear();
scanf("%d%d", &p, &n);
for(int i = ; i <= p; i++) {
int k; scanf("%d", &k);
for(int j = ; j < k; j++) {
int a; scanf("%d", &a);
g[i].push_back(a);
}
}
int res = hungary();
//cout<<res<<endl;
if(res == p) printf("YES\n");
else printf("NO\n");
}
}

poj-1469-COURSES-二分图匹配-匈牙利算法(模板)的更多相关文章

  1. POJ1469 COURSES 二分图匹配 匈牙利算法

    原文链接http://www.cnblogs.com/zhouzhendong/p/8232649.html 题目传送门 - POJ1469 题意概括 在一个大矩阵中,有一些障碍点. 现在让你用1*2 ...

  2. USACO 4.2 The Perfect Stall(二分图匹配匈牙利算法)

    The Perfect StallHal Burch Farmer John completed his new barn just last week, complete with all the ...

  3. HDU 5943 Kingdom of Obsession 【二分图匹配 匈牙利算法】 (2016年中国大学生程序设计竞赛(杭州))

    Kingdom of Obsession Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  4. HDU 2444 - The Accomodation of Students - [二分图判断][匈牙利算法模板]

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=2444 Time Limit: 5000/1000 MS (Java/Others) Mem ...

  5. poj 1469 COURSES (二分图模板应用 【*模板】 )

    COURSES Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 18454   Accepted: 7275 Descript ...

  6. P3386 【模板】二分图匹配(匈牙利算法)

    题目背景 二分图 题目描述 给定一个二分图,结点个数分别为n,m,边数为e,求二分图最大匹配数 输入输出格式 输入格式: 第一行,n,m,e 第二至e+1行,每行两个正整数u,v,表示u,v有一条连边 ...

  7. [洛谷P3386] [模板] 二分图匹配 (匈牙利算法)

    题目传送门 毒瘤出题人zzk出了个二分图匹配的题(18.10.04模拟赛T2),逼我来学二分图匹配. 网络流什么的llx讲完之后有点懵,还是匈牙利比较好理解(绿与被绿). 对于左边的点一个一个匹配,记 ...

  8. luogu3386 【模板】二分图匹配 匈牙利算法 hdu2063 过山车 dinic

    luogu 匈牙利算法 #include <iostream> #include <cstring> #include <cstdio> using namespa ...

  9. Codevs 1222 信与信封问题 二分图匹配,匈牙利算法

    题目: http://codevs.cn/problem/1222/ 1222 信与信封问题   时间限制: 1 s   空间限制: 128000 KB   题目等级 : 钻石 Diamond 题解 ...

  10. (转)二分图匹配匈牙利算法与KM算法

    匈牙利算法转自于: https://blog.csdn.net/dark_scope/article/details/8880547 匈牙利算法是由匈牙利数学家Edmonds于1965年提出,因而得名 ...

随机推荐

  1. CentOS 6.5下Git服务器搭建

    1 . Git服务器搭建 1. 环境部署 系统环境:服务器端:CentOS 6.5 ,ip:192.168.56.1 客户端:CentOS 6.5 ,ip:192.168.56.101 软件版本:服务 ...

  2. 【bzoj1008】[HNOI2008]越狱

    1008: [HNOI2008]越狱 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 7692  Solved: 3296[Submit][Status] ...

  3. HTTP persistent connection

    http://en.wikipedia.org/wiki/HTTP_persistent_connection

  4. 实现WMSservice的时候,出现边缘的点或icon被切断的情况

    可以通过为实际查询的boundary加一个buffer,使查询的范围比指定的大一点点,这样就会使tile之间在查询的时候有一定的重叠. 如:Geometry queryBoundary = JTS.t ...

  5. POJ 1552

    #include<iostream> using namespace std; int main() { ]; int i,j; ; do{ sum=; ;num[i-]!=&&a ...

  6. DF学Mysql(三)——Mysql数据类型

    Mysql数据类型分为:整数类型.浮点数类型.定点数类型日期与时间类型字符串类型二进制类型 整数类型 字节数 无符号数取值范围 有符号数取值范围TINYINT 1 0-255 -128-127SMAL ...

  7. C# 工厂

    /// <summary> /// 创造实例 /// </summary> /// <typeparam name="T">类型</typ ...

  8. php怎么获取checkbox复选框的内容?

    由于checkbox属性,所有必须把checkbox复选择框的名字设置为一个如果checkbox[],php才能读取,以数据形式,否则不能正确的读取checkbox复选框的值哦. <form n ...

  9. Codeforces Round #336 (Div. 2) B. Hamming Distance Sum 计算答案贡献+前缀和

    B. Hamming Distance Sum   Genos needs your help. He was asked to solve the following programming pro ...

  10. poj 3615(floyd变形)

    题目链接:http://poj.org/problem?id=3615 思路:map[i][j]表示顶点i,j之间的最高的障碍物,于是题目要求的是最高障碍物的最小值,不就是min(map[i][j], ...