Gym - 101915D Largest Group 最大团
给你一个二分图 问你最大团为多大
解一:状压DP
解二:二分图最大匹配
二分图的最大团=补图的最大独立集
二分图最大独立集=二分图定点个数-最大匹配
//Hungary
#include<bits/stdc++.h>
using namespace std;
#define N 50
int useif[N]; //记录y中节点是否使用 0表示没有访问过,1为访问过
int link[N]; //记录当前与y节点相连的x的节点
int mat[N][N]; //记录连接x和y的边,如果i和j之间有边则为1,否则为0
int gn, gm; //二分图中x和y中点的数目
int can(int t) {
int i;
for (i = ; i <= gm; i++) {
if (useif[i] == && mat[t][i]) {
useif[i] = ;
if (link[i] == - || can(link[i])) {
link[i] = t;
return ;
}
}
}
return ;
}
int MaxMatch() {
int i, num;
num = ;
memset(link, 0xff, sizeof(link));
for (i = ; i <= gn; i++) {
memset(useif, , sizeof(useif));
if (can(i)) {
num++;
}
}
return num;
}
int main() {
int TCASE;
scanf("%d", &TCASE);
while (TCASE--) {
int n, k;
int u, v;
scanf("%d %d", &n, &k);
gn = gm = n;
memset(mat, , sizeof(mat));
for (int i = ; i <= k; i++) {
scanf("%d %d", &u, &v);
mat[u][v] = ;
}
for (int i = ; i <= n; i++) {
for (int j = ; j <= n; j++) {
mat[i][j] = mat[i][j] ^ ;
}
}
int ans = n * ;
ans -= MaxMatch();
printf("%d\n", ans);
}
}
Gym - 101915D Largest Group 最大团的更多相关文章
- POJ2985 The k-th Largest Group[树状数组求第k大值+并查集||treap+并查集]
The k-th Largest Group Time Limit: 2000MS Memory Limit: 131072K Total Submissions: 8807 Accepted ...
- POJ 2985 The k-th Largest Group(树状数组 并查集/查找第k大的数)
传送门 The k-th Largest Group Time Limit: 2000MS Memory Limit: 131072K Total Submissions: 8690 Acce ...
- poj 2985 The k-th Largest Group 树状数组求第K大
The k-th Largest Group Time Limit: 2000MS Memory Limit: 131072K Total Submissions: 8353 Accepted ...
- 【POJ2985】【Treap + 并查集】The k-th Largest Group
Description Newman likes playing with cats. He possesses lots of cats in his home. Because the numbe ...
- POJ2985 The k-th Largest Group (并查集+treap)
Newman likes playing with cats. He possesses lots of cats in his home. Because the number of cats is ...
- Gym 101775A - Chat Group - [简单数学题][2017 EC-Final Problem A]
题目链接:http://codeforces.com/gym/101775/problem/A It is said that a dormitory with 6 persons has 7 cha ...
- Gym - 101775A Chat Group 组合数+逆元+快速幂
It is said that a dormitory with 6 persons has 7 chat groups ^_^. But the number can be even larger: ...
- POJ2985 The k-th Largest Group treap
POJ2985 比较简单的平衡树题目 树内不要添加容量为1的节点 否则会超时. #include<iostream> #include<cstdio> #include< ...
- 【LeetCode】1399. 统计最大组的数目 Count Largest Group
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 直接求 日期 题目地址:https://leetcod ...
随机推荐
- java:Echarts,POI
1.Echarts: demo.js: function demo(selector){ var myEcharts=echarts.init(selector); var option = { ti ...
- ubuntu install themes && use it
one step: I am going to show you the installation of a theme with Numix theme and Unity Tweak Tool. ...
- python计算机二级考试知识点——文件操作
1. 文件的使用:文件打开.关闭和读写 python通过open函数打开一个文件,并返回一个操作文件的变量,语法形式如下: <变量名>=open(<文件路劲及文件名>,< ...
- ubuntu查看目录大小
du -h --max-depth=1 该命令会查看目录下的所有子目录大小,以及目录总共占用磁盘空间
- mysql --single-transaction 在从库导入完数据以后要在配置文件/etc/my.cnf 中加上read_only=1的参数
1.在做数据库的主从时,防止在这个过程中,有数据访问进来,要: 要想连super权限用户的写操作也禁止,就使用"flush tables with read lock;",这样设置 ...
- .NET Core和.NET Standard 区别与联系
每一种托管实现(如Xamarin..NET Core或.NET Framework)都必须遵循.NET Standard实现BCL..NET STANDARD LIBRARY是.net 标准库,.NE ...
- python 爬虫 urllib模块 反爬虫机制UA
方法: 使用urlencode函数 urllib.request.urlopen() import urllib.request import urllib.parse url = 'https:// ...
- [Python3] 041 文件 持久化
目录 文件 持久化 1. pickle 1.1 例子1 1.2 例子2 1.3 注意 2. shelve 2.1 举例 2.2 特性 2.3 强制写回 2.4 使用 with 管理上下文环境 文件 持 ...
- PTA(Basic Level)1028.人口普查
某城镇进行人口普查,得到了全体居民的生日.现请你写个程序,找出镇上最年长和最年轻的人. 这里确保每个输入的日期都是合法的,但不一定是合理的--假设已知镇上没有超过 200 岁的老人,而今天是 2014 ...
- mysql jdbc url
地址为jdbc:mysql://localhost:3306/mymiaosha?characterEncoding=utf-8时访问时可能会出现下图提示 地址改为jdbc:mysql://local ...