HDU 1083 二分图匹配
来源:互联网 发布:大数据和云计算的关系 编辑:程序博客网 时间:2024/05/19 04:27
建立二分图,x集合是课程,y集合是学生。我们求最大匹配数,如果最大匹配数等于|x|那么每个课程都可以找到一个代表,反之找不到
#pragma warning(disable:4996);#include <algorithm>#include <iostream>#include <cstring>#include <cstdlib>#include <cstdio>#include <cmath>#include <queue>#include <new>#include <set>#include <map>using namespace std;typedef long long int LL;const double pi = (acos(-1));const int maxn = 1000;int g[maxn][maxn], used[maxn], link[maxn];int nx, ny;bool dfs (int u) {for (int v = 1; v <= ny; v++) {if (g[u][v] && !used[v]) {used[v] = 1;if (link[v] == -1 || dfs (link[v])) {link[v] = u;return true;}}}return false;}int maxmatch () {int res = 0;memset (link, -1, sizeof (link));for (int i = 1; i <= nx; i++) {memset (used, 0, sizeof (used));if (dfs (i)) res++;}return res;}int main(){//freopen("D:\\Test_in.txt", "r", stdin);//freopen("D:\\Test_out.txt", "w", stdout);int T;scanf ("%d", &T);while (T--) {scanf ("%d%d", &nx, &ny);memset (g, 0, sizeof (g));for (int i = 1; i <= nx; i++) {int n;scanf ("%d", &n);for (int j = 0; j < n; j++) {int a;scanf ("%d", &a);g[i][a] = 1;}}int ans = maxmatch ();if (ans == nx) printf ("YES\n");else printf ("NO\n");}return 0;}
0 0
- HDU 1083 二分匹配图
- HDU 1083 二分图匹配
- HDU 1083 二分匹配
- hdu 1083 二分匹配
- HDU 1083 二分匹配
- hdu 1083 Courses (二分图匹配)
- hdu 1083 Courses 二分图最大匹配
- HDU 1083 Coures(二分图匹配)
- hdu 1083 Courses(二分图匹配)
- HDU 1083 Courses(二分图匹配)
- hdu 1083 Courses(二分图最大匹配)
- HDU 1083 COURSES 【二分图最大匹配】
- hdu 1083 Courses(二分图最大匹配)
- HDU OJ 1083 Courses 【二分图匹配之最大匹配】
- HDU 1083 二分匹配 Courses
- HDU-1083-Courses [二分匹配]
- HDU-2063 二分图匹配
- HDU-2444 二分图匹配
- Linux下磁盘的挂载与卸载
- HEVC码率控制(二):从compressGOP()到compressSlice()
- Android----按钮单击事件的四种写法
- centos7 网卡名字改为eth0
- 代码中适配
- HDU 1083 二分图匹配
- UVA.232 Crossword Answers
- numpy基本使用方法示例
- winform窗体上的超链接怎么跳转到网页?
- bLue的文件查找器
- c ide开发工具
- Spring方法注入
- nginx的sysV init脚本
- 图的应用