题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=26913

思路:水题一枚,就是求最大独立集。最大独立集=顶点数-最大匹配。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
#define MAXN 1111
#define FILL(a,b) memset(a,b,sizeof(a)) int n,m,ly[MAXN];
bool mark[MAXN]; vector<int>g[MAXN]; int dfs(int u)
{
for(int i=;i<g[u].size();i++){
int v=g[u][i];
if(!mark[v]){
mark[v]=true;
if(ly[v]==-||dfs(ly[v])){
ly[v]=u;
return ;
}
}
}
return ;
} int MaxMatch()
{
int res=;
FILL(ly,-);
for(int i=;i<=n;i++){
FILL(mark,false);
res+=dfs(i);
}
return res/;
} int main()
{
int _case,u,v,t=;
scanf("%d",&_case);
while(_case--){
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)g[i].clear();
while(m--){
scanf("%d%d",&u,&v);
g[u].push_back(v);
g[v].push_back(u);
}
printf("Case %d: %d\n",t++,n-MaxMatch());
}
return ;
}

loj 1201(最大独立集)的更多相关文章

  1. LOJ #2540. 「PKUWC 2018」随机算法(概率dp)

    题意 LOJ #2540. 「PKUWC 2018」随机算法 题解 朴素的就是 \(O(n3^n)\) dp 写了一下有 \(50pts\) ... 大概就是每个点有三个状态 , 考虑了但不在独立集中 ...

  2. [LOJ#526]「LibreOJ β Round #4」子集

    [LOJ#526]「LibreOJ β Round #4」子集 试题描述 qmqmqm有一个长为 n 的数列 a1,a2,……,an,你需要选择集合{1,2,……,n}的一个子集,使得这个子集中任意两 ...

  3. poj 3692 Kindergarten (最大独立集)

    Kindergarten Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4903   Accepted: 2387 Desc ...

  4. 【BZOJ-4316】小C的独立集 仙人掌DP + 最大独立集

    4316: 小C的独立集 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 57  Solved: 41[Submit][Status][Discuss] ...

  5. LA 3415 (二分图+最大独立集)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  6. codevs 1201 最小数和最大数

    http://codevs.cn/problem/1201/ 1201 最小数和最大数  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 青铜 Bronze 题解       题 ...

  7. Poj(2771),最大独立集

    题目链接:http://poj.org/problem?id=2771 Guardian of Decency Time Limit: 3000MS   Memory Limit: 65536K To ...

  8. Poj(1466),最大独立集,匈牙利算法

    题目链接:http://poj.org/problem?id=1466 Girls and Boys Time Limit: 5000MS   Memory Limit: 10000K Total S ...

  9. POJ 2771 二分图(最大独立集)

    Guardian of Decency Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 5244   Accepted: 21 ...

随机推荐

  1. Python模块之optparse

    参考: http://www.cnblogs.com/captain_jack/archive/2011/01/11/1933366.html https://docs.python.org/2/li ...

  2. wxPython中文教程入门实例

    这篇文章主要为大家分享下python编程中有关wxPython的中文教程,分享一些wxPython入门实例,有需要的朋友参考下     wxPython中文教程入门实例 wx.Window 是一个基类 ...

  3. Match:Blue Jeans(POJ 3080)

    DNA序列 题目大意:给你m串字符串,要你找最长的相同的连续字串 这题暴力kmp即可,注意要按字典序排序,同时,是len<3才输出no significant commonalities #in ...

  4. 【leetcode】Rotate List(middle)

    Given a list, rotate the list to the right by k places, where k is non-negative. For example:Given 1 ...

  5. IOS-01零碎知识总结

    1. 变量的@public @private @package @protected 声明有什么含义? @public  可以被所有的类访问 @private  只有该类的方法可以访问,子类的都不能访 ...

  6. 让div等块级元素水平以及垂直居中的解决办法

    一.背景 我们在设计页面的时候,经常要把div等块级元素居中显示,而且是相对页面窗口水平和垂直方向居中显示,如让登录窗口居中显示.我们传统解决的办法是用纯CSS来让div等块级元素居中.在本文中,我将 ...

  7. 如何在MyEclipse中通过hibernate使用jtds驱动连接数据库,并向数据库添加数据的方法

    最近学习了下如何在MyEclipse中通过hibernate使用jtds驱动连接数据库,并向数据库添加数据的方法,虽然MyEclipse中自带了连接数据库的方法,我也尝试了下其他方法,如有不当之处请指 ...

  8. October 12th 2016 Week 42nd Wednesday

    Passion is momentary; love is enduring. 激情短暂,真爱长久. What is love? And what is real love? We are alway ...

  9. August 19th 2016 Week 34th Friday

    Friends are not the people you meet at the top, they are the people who were with you at the bottom. ...

  10. Eclipse 安装SVN

    地址:http://wenku.baidu.com/link?url=ntQy2-1CjlNyUpO0-4uhROrc9jCo12Yifh7MkPULmY_dCybl6SEH99SxYxEbZQEiW ...