给你一个二分图 问你最大团为多大

解一:状压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 最大团的更多相关文章

  1. POJ2985 The k-th Largest Group[树状数组求第k大值+并查集||treap+并查集]

    The k-th Largest Group Time Limit: 2000MS   Memory Limit: 131072K Total Submissions: 8807   Accepted ...

  2. POJ 2985 The k-th Largest Group(树状数组 并查集/查找第k大的数)

    传送门 The k-th Largest Group Time Limit: 2000MS   Memory Limit: 131072K Total Submissions: 8690   Acce ...

  3. poj 2985 The k-th Largest Group 树状数组求第K大

    The k-th Largest Group Time Limit: 2000MS   Memory Limit: 131072K Total Submissions: 8353   Accepted ...

  4. 【POJ2985】【Treap + 并查集】The k-th Largest Group

    Description Newman likes playing with cats. He possesses lots of cats in his home. Because the numbe ...

  5. 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 ...

  6. 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 ...

  7. Gym - 101775A Chat Group 组合数+逆元+快速幂

    It is said that a dormitory with 6 persons has 7 chat groups ^_^. But the number can be even larger: ...

  8. POJ2985 The k-th Largest Group treap

    POJ2985 比较简单的平衡树题目 树内不要添加容量为1的节点 否则会超时. #include<iostream> #include<cstdio> #include< ...

  9. 【LeetCode】1399. 统计最大组的数目 Count Largest Group

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 直接求 日期 题目地址:https://leetcod ...

随机推荐

  1. Oracle11g安装出现时未能满足某些最低安装要求

    需要开启C盘共享,才能检测硬件是否满足要求.cmd命令:net share c$=c::或者勾选全部忽略,继续下一步安装. 可参考https://blog.csdn.net/huazicomeon/a ...

  2. Tor路径选择说明

    Tor Path Specification Roger Dingledine Nick Mathewson Note: This is an attempt to specify Tor as cu ...

  3. 03 vue项目结构

    上一篇已介绍根据vue-cli创建项目,本篇介绍根据vue-cli官方脚手架创建的项目的项目结构. 一.图看结构 build  [webpack配置]         webpack相关配置,都已经配 ...

  4. (C#)Appium自动化测试之mobile:shell输入法

    1.ADB执行Shell命令 a.如果电脑上已装Appium,那么需要在高级设置里勾选 Relaxed Security. 如图:     b.cmd命令行启动appium appium --rela ...

  5. /etc/passwd字段信息

    root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nol ...

  6. KVM虚拟化网络管理(4)

    一.Linux Bridge网桥管理 网络虚拟化是虚拟化技术中最复杂的部分,也是非常重要的资源.第一节中我们创建了一个名为br0的linux-bridge网桥,如果在此网桥上新建一台vm,如下图: V ...

  7. 闲记Windows 取证艺术

         是不是很好奇,别人能够在你电脑上查看你运行程序历史,文档使用痕迹,浏览器浏览历史种种历史痕迹,没错,通过简单的系统了解以及配合相对应的工具,这一切就是这么的简单,看起来很高大上的操作,其实是 ...

  8. win10任务切换变卡

    问题:更新之前没有任何问题,用alt+tab是秒切,更新后切换任务后会黑屏一两秒然后才转到切换页面 解决方法:关闭服务“system interface foundation service”

  9. Java中的锁-悲观锁、乐观锁,公平锁、非公平锁,互斥锁、读写锁

    总览图 如果文中内容有错误,欢迎指出,谢谢. 悲观锁.乐观锁 悲观锁.乐观锁使用场景是针对数据库操作来说的,是一种锁机制. 悲观锁(Pessimistic Lock):顾名思义,就是很悲观,每次去拿数 ...

  10. python 爬虫 基于requests模块的get请求

    需求:爬取搜狗首页的页面数据 import requests # 1.指定url url = 'https://www.sogou.com/' # 2.发起get请求:get方法会返回请求成功的响应对 ...