Codeforces Round #533 (Div. 2) E 最大独立集
知识点
最大独立集(set) = 补图的最大团(clique )
最小顶点覆盖 + 最大独立集 = V
2 seconds
256 megabytes
standard input
standard output
Hiasat registered a new account in NeckoForces and when his friends found out about that, each one of them asked to use his name as Hiasat's handle.
Luckily for Hiasat, he can change his handle in some points in time. Also he knows the exact moments friends will visit his profile page. Formally, you are given a sequence of events of two types:
- 11 — Hiasat can change his handle.
- 22 ss — friend ss visits Hiasat's profile.
The friend ss will be happy, if each time he visits Hiasat's profile his handle would be ss.
Hiasat asks you to help him, find the maximum possible number of happy friends he can get.
The first line contains two integers nn and mm (1≤n≤105,1≤m≤401≤n≤105,1≤m≤40) — the number of events and the number of friends.
Then nn lines follow, each denoting an event of one of two types:
- 11 — Hiasat can change his handle.
- 22 ss — friend ss (1≤|s|≤401≤|s|≤40) visits Hiasat's profile.
It's guaranteed, that each friend's name consists only of lowercase Latin letters.
It's guaranteed, that the first event is always of the first type and each friend will visit Hiasat's profile at least once.
Print a single integer — the maximum number of happy friends.
5 3
1
2 motarack
2 mike
1
2 light
2
4 3
1
2 alice
2 bob
2 tanyaromanova
1
In the first example, the best way is to change the handle to the "motarack" in the first event and to the "light" in the fourth event. This way, "motarack" and "light" will be happy, but "mike" will not.
In the second example, you can choose either "alice", "bob" or "tanyaromanova" and only that friend will be happy.
题意 m个朋友 n个操作
两种操作
1 Hiasat 可以修自己的id为任意值
2 Hiasat 得一个朋友查看id
当且仅当 他的朋友每次查看id都为自己的名字才是高兴的
解析 很容易想到两个1之间的朋友是互斥的 只能使其中一名朋友高兴,我们在互斥的朋友之间连一条无向边,从而转化成求无向图的最大独立集问题。
AC代码
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define fillchar(a, x) memset(a, x, sizeof(a))
#define huan printf("\n")
#define debug(a,b) cout<<a<<" "<<b<<" "<<endl
#define ffread(a) fastIO::read(a)
using namespace std;
const int maxn = 1e5+;
const int maxm = 1e4+;
const int inf = 0x3f3f3f3f;
const int mod = ;
const double epx = 1e-;
typedef long long ll;
const ll INF = 1e18;
const double pi = acos(-1.0);
//head------------------------------------------------------------------
int G[][];
int ans,cnt[],group[],n,m,vis[];//ans表示最大团,cnt[N]表示当前最大团的节点数,group[N]用以寻找一个最大团集合
map<string,int> pm;
int tot = ;
struct node
{
int op;
string s;
} Q[maxn];
vector<int> v;
bool dfs(int u,int pos)//u为当从前顶点开始深搜,pos为深搜深度(即当前深搜树所在第几层的位置)
{
int i,j;
for(i=u+; i<=tot; i++) //按递增顺序枚举顶点
{
if(cnt[i]+pos<=ans)
return ;//剪枝
if(G[u][i])
{
// 与目前团中元素比较,取 Non-N(i)
for(j=; j<pos; j++)
if(!G[i][vis[j]])
break;
if(j==pos)
{
// 若为空,则皆与 i 相邻,则此时将i加入到 最大团中
vis[pos]=i;//深搜层次也就是最大团的顶点数目,vis[pos] = i表示当前第pos小的最大团元素为i(因为是按增顺序枚举顶点 )
if(dfs(i,pos+))
return ;
}
}
}
if(pos>ans)
{
for(i=; i<pos; i++)
group[i] = vis[i]; // 更新最大团元素
ans = pos;
return ;
}
return ;
}
void maxclique()//求最大团
{
ans=-;
for(int i=tot; i>; i--)
{
vis[]=i;
dfs(i,);
cnt[i]=ans;
}
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=; i<=n; i++)
{
int op;
string tmp;
scanf("%d",&op);
if(op==)
Q[i].op = op;
else
{
cin>>tmp;
Q[i].op = op;
Q[i].s = tmp;
if(!pm[tmp])
pm[tmp] = ++tot;
}
}
memset(G,inf,sizeof(G));
Q[n+].op=;
for(int i=; i<=n+; i++)
{
if(Q[i].op==)
{
for(int j=; j<v.size(); j++)
{
for(int k=j+; k<v.size(); k++)
{
G[v[k]][v[j]] = ;
G[v[j]][v[k]] = ;
}
}
v.clear();
}
else
{
v.push_back(pm[Q[i].s]);
}
}
maxclique();
if(ans<)
ans = ;
printf("%d\n",ans);
return ;
}
Codeforces Round #533 (Div. 2) E 最大独立集的更多相关文章
- Codeforces Round #533 (Div. 2)题解
link orz olinr AK Codeforces Round #533 (Div. 2) 中文水平和英文水平都太渣..翻译不准确见谅 T1.给定n<=1000个整数,你需要钦定一个值t, ...
- Codeforces Round #533 (Div. 2) E. Helping Hiasat(最大独立集)
题目链接:https://codeforces.com/contest/1105/problem/E 题意:有 n 个事件,op = 1 表示我可以修改昵称,op = 2 表示一个名为 s_i 的朋友 ...
- Codeforces Round #533 (Div. 2) C.思维dp D. 多源BFS
题目链接:https://codeforces.com/contest/1105 C. Ayoub and Lost Array 题目大意:一个长度为n的数组,数组的元素都在[L,R]之间,并且数组全 ...
- Codeforces Round #533 (Div. 2)
C: 题意: 有n个整数ai,数列a有两个神奇的性质.1.所有的整数都在[l,r]范围内.2.这n个数的和能被3整除.现在给出l和r,和个数n,问你有多少种方法构造出数列a,方案数mod1e9+7. ...
- Codeforces Round #533 (Div. 2) Solution
A. Salem and Sticks 签. #include <bits/stdc++.h> using namespace std; #define N 1010 int n, a[N ...
- Codeforces Round #533 (Div. 2) C. Ayoub and Lost Array 【dp】
传送门:http://codeforces.com/contest/1105/problem/C C. Ayoub and Lost Array time limit per test 1 secon ...
- Codeforces Round #533 (Div. 2) B. Zuhair and Strings 【模拟】
传送门:http://codeforces.com/contest/1105/problem/B B. Zuhair and Strings time limit per test 1 second ...
- Codeforces Round #533(Div. 2) C.Ayoub and Lost Array
链接:https://codeforces.com/contest/1105/problem/C 题意: 给n,l,r. 一个n长的数组每个位置可以填区间l-r的值. 有多少种填法,使得数组每个位置相 ...
- Codeforces Round #533(Div. 2) D.Kilani and the Game
链接:https://codeforces.com/contest/1105/problem/D 题意: 给n*m的地图,最多9个人,同时有每个人的扩张次数(我开始以为是直线扩张最大长度..实际是能连 ...
随机推荐
- idea 下maven 导入本地jar,以及导入之后 java不能引用问题
1.在当前的项目中新建立一个lib文件夹,将需要导入的jar放入其中. 2.配置pom.xml 文件 <!--导入本地jar--> <dependency> <group ...
- UVA 11419 SAM I AM (最小点覆盖,匈牙利算法)
题意:给一个r*c的矩阵,某些格子中可能有一些怪物,可以在一行或一列防止一枚大炮,大炮会扫光整行/列的怪,问最少需要多少炮?输出炮的位置. 思路: 先每行和列都放一个炮,把炮当成点,把怪当成边,一边连 ...
- 如何修改开发板主频--迅为iMX6UL开发板
平台:iMX6UL开发板 iMX6UL开发板 可以在文件系统中通过命令修改 CPU 运行的主频.如下图所示,使用命令“cat /sys/devices/system/cpu/cpu ...
- 关于js中的then(盗)
then()相关的东西包括但不限于:promise,thien.js 虽然还没彻底搞清楚这些个玩意儿,但是 现在知道了 then()是干嘛的了 最主要的,是解决了异步方法立刻返回的问题 这个特性 ...
- linux_2
mac和linux上默认安装着SSH客户端,Windows上需要自己安装个软件. Windows下SSH客户端的安装:建议从官方网站下载正式程序安装(免费) Putty:https://www.chi ...
- Omnidirectional DSO: Direct Sparse Odometry with Fisheye Cameras 论文摘要
1. Abstract 通过一种Unified Omnidirectional Model作为投影方程. 这种方式可以使用图像的所有内容包括有强畸变的区域,而现存的视觉里程计方案只能修正或者切掉来使用 ...
- hdu 6441 Find Integer(费马大定理+勾股数)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6441(本题来源于2018年中国大学生程序设计竞赛网络选拔赛) 题意:输入n和a,求满足等式a^n+b^ ...
- [LOJ] 分块九题 7
区间加法,区间乘法,单点查询. 洛谷线段树2 屡清加法乘法的关系,定义答案为 a*mut+add 对于整块: 新的乘w,mut和add都要乘w 新的加w,add加w //Stay foolish,st ...
- (7) openssl dgst(生成和验证数字签名)
该伪命令是单向加密工具,用于生成文件的摘要信息 也可以进行数字签名,及验证数字签名. 首先要明白的是,数字签名的过程是计算出摘要信息,然后使用私钥对摘要信息进行加密得 ...
- phpize Cannot find autoconf. 错误解决
phpize Configuring for: PHP Api Version: 20151012 Zend Module Api No: 20151012 Zend Extension Api No ...