最大独立集 HDU 1068
题目大意:有n个人,两个人之间有相互的关系,问最大的关系数目。
思路:n-(最大匹配数/2)。因为这里给出的是n个人之间的两两关系
//看看会不会爆int!数组会不会少了一维!
//取物问题一定要小心先手胜利的条件
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define haha; printf("haha\n");
const int maxn = + ;
int myleft[maxn];
int T[maxn];
bool vis[maxn][maxn];
vector<int> G[maxn];
int n; bool match(int u){
int len = G[u].size();
for (int i = ; i < len; i++){
int v = G[u][i];
if (!T[v]){
T[v] = true;
if (myleft[v] == - || match(myleft[v])){
myleft[v] = u;
return true;
}
}
}
return false;
} int main(){
while (scanf("%d", &n) == ){
for (int i = ; i < n; i++){
for (int j = ; j < n; j++){
vis[i][j] = false;
}
G[i].clear();
}
for (int i = ; i <= n; i++){
int k, u;
scanf("%d: (%d)", &u, &k);
for (int i = ; i < k; i++){
int v; scanf("%d", &v);
G[u].push_back(v);
vis[u][v] = true;
}
}
memset(myleft, -, sizeof(myleft));
int ans = ;
for (int i = ; i < n; i++){
memset(T, , sizeof(T));
ans += match(i);
}
for (int i = ; i < n; i++){
printf("left[%d] = %d\n", i, myleft[i]);
}
printf("%d\n", n - ans / );
}
return ;
}
最大独立集 HDU 1068的更多相关文章
- HDU 1068 Girls and Boys(最大独立集合 = 顶点数 - 最大匹配数)
HDU 1068 :题目链接 题意:一些男孩和女孩,给出一些人物关系,然后问能找到最多有多少个人都互不认识. 转换一下:就是大家都不认识的人,即最大独立集合 #include <iostream ...
- HDU 1068 Girls and Boys (二分图最大独立集)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1068 有n个同学,格式ni:(m) n1 n2 n3表示同学ni有缘与n1,n2,n3成为情侣,求集合 ...
- HDU 1068 Girls and Boys(最大独立集)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1068 题目大意:有n个人,一些人认识另外一些人,选取一个集合,使得集合里的每个人都互相不认识,求该集合 ...
- hdu - 1068 Girls and Boys (二分图最大独立集+拆点)
http://acm.hdu.edu.cn/showproblem.php?pid=1068 因为没有指定性别,所以要拆点,把i拆分i和i’ 那么U=V-M (M是最大匹配,U最大独立集,V是顶点数) ...
- (step6.3.2)hdu 1068(Girls and Boys——二分图的最大独立集)
题目大意:第一行输入一个整数n,表示有n个节点.在接下来的n行中,每行的输入数据的格式是: 1: (2) 4 6 :表示编号为1的人认识2个人,他们分别是4.6: 求,最多能找到多少个人,他们互不认识 ...
- HDU 1068 Girls and Boys 二分图最大独立集(最大二分匹配)
Girls and Boys Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- Girls and Boys HDU - 1068 二分图匹配(匈牙利)+最大独立集证明
最大独立集证明参考:https://blog.csdn.net/qq_34564984/article/details/52778763 最大独立集证明: 上图,我们用两个红色的点覆盖了所有边.我们证 ...
- hdu 1068 Girls and Boys(匈牙利算法求最大独立集)
Girls and Boys Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU - 1068 Girls and Boys(二分匹配---最大独立集)
题意:给出每个学生的标号及与其有缘分成为情侣的人的标号,求一个最大集合,集合中任意两个人都没有缘分成为情侣. 分析: 1.若两人有缘分,则可以连一条边,本题是求一个最大集合,集合中任意两点都不相连,即 ...
随机推荐
- MVC创建
[1]创建ASP.NET_MVC应用程序 1>新建项目>web>Visual Studio 2012>ASP.NET MVC4 Web应用程序 2>填写名称,位置 ...
- python连接MongoDB
1.安装pymongo库 windows下: pip install pymongo 或者 easy_install install pymongo 2.使用pymongo模块连接mongoDB数据库 ...
- 分布式日志收集系统Apache Flume的设计详细介绍
问题导读: 1.Flume传输的数据的基本单位是是什么? 2.Event是什么,流向是怎么样的? 3.Source:完成对日志数据的收集,分成什么打入Channel中? 4.Channel的作用是什么 ...
- Vue.js 组件笔记
Vue 组件总结笔记 一. 创建组件 1. 使用组件三部曲 ( 创建, 注册, 使用 ) 2. 全局组件:Vue.component('tag', {}); 3. 局部组件: components 属 ...
- java 视频中截图
package com.sun.test; import java.io.File; import java.util.List; public class CreatePh { //public s ...
- Python 常见错误
1. def func(): return a=3#错误的用法 2. class a: def func():#func至少要有一个self参数 ........................... ...
- POJ 1328 Radar Installation#贪心(坐标几何题)
(- ̄▽ ̄)-* #include<iostream> #include<cstdio> #include<algorithm> #include<cmath ...
- C程序浅议
文件FILE是程序设计中的一个重要概念.所谓“文件”一般是指存储在外部介质上的数据的集合.操作系统是以文件为单位对数据进行管理的,而文件是以文件名为标识的.操作系统对文件实行“按名存取”. C语言把文 ...
- 大数加法(STL list)
#include<iostream> #include<list> #include<string> using namespace std; int main() ...
- webapi中常用attribute标签
HTTP Methods Instead of using the naming convention for HTTP methods, you can explicitly specify the ...