知识点

最大独立集(set) = 补图的最大团(clique )

最小顶点覆盖 + 最大独立集 = V

E. Helping Hiasat
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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.

Output

Print a single integer — the maximum number of happy friends.

Examples
input

Copy
5 3
1
2 motarack
2 mike
1
2 light
output

Copy
2
input

Copy
4 3
1
2 alice
2 bob
2 tanyaromanova
output

Copy
1
Note

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 最大独立集的更多相关文章

  1. Codeforces Round #533 (Div. 2)题解

    link orz olinr AK Codeforces Round #533 (Div. 2) 中文水平和英文水平都太渣..翻译不准确见谅 T1.给定n<=1000个整数,你需要钦定一个值t, ...

  2. Codeforces Round #533 (Div. 2) E. Helping Hiasat(最大独立集)

    题目链接:https://codeforces.com/contest/1105/problem/E 题意:有 n 个事件,op = 1 表示我可以修改昵称,op = 2 表示一个名为 s_i 的朋友 ...

  3. Codeforces Round #533 (Div. 2) C.思维dp D. 多源BFS

    题目链接:https://codeforces.com/contest/1105 C. Ayoub and Lost Array 题目大意:一个长度为n的数组,数组的元素都在[L,R]之间,并且数组全 ...

  4. Codeforces Round #533 (Div. 2)

    C: 题意: 有n个整数ai,数列a有两个神奇的性质.1.所有的整数都在[l,r]范围内.2.这n个数的和能被3整除.现在给出l和r,和个数n,问你有多少种方法构造出数列a,方案数mod1e9+7. ...

  5. Codeforces Round #533 (Div. 2) Solution

    A. Salem and Sticks 签. #include <bits/stdc++.h> using namespace std; #define N 1010 int n, a[N ...

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

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

  8. Codeforces Round #533(Div. 2) C.Ayoub and Lost Array

    链接:https://codeforces.com/contest/1105/problem/C 题意: 给n,l,r. 一个n长的数组每个位置可以填区间l-r的值. 有多少种填法,使得数组每个位置相 ...

  9. Codeforces Round #533(Div. 2) D.Kilani and the Game

    链接:https://codeforces.com/contest/1105/problem/D 题意: 给n*m的地图,最多9个人,同时有每个人的扩张次数(我开始以为是直线扩张最大长度..实际是能连 ...

随机推荐

  1. Oracle AWR报告的生成

    生成AWR报告需要dbms_workload_repository包的权限. 一.以oracle用户登录到数据库服务器 二.进入SQLPLUS 三.执行脚本 @?/rdbms/admin/awrrpt ...

  2. MATLAB GUI制作快速入门

    创建空白的GUI在MATLAB命令行中输入guide新建GUI,选择Blank GUI (Default),点击确定后就生成了一个空白的GUI制作界面,如下图所示 图1制作GUI的具体过程简单加法器将 ...

  3. docker 新手入门 (阿里镜像仓库的使用)

    创建镜像仓库后的步骤是:   https://help.aliyun.com/document_detail/60743.html?spm=a2c4g.11186623.6.546.79be52f3y ...

  4. js toString() 方法 Number() 方法 等 类型转换

    1.1 数字类型转字符串 String() 变量.toString() toString() 方法 toString() 方法可把一个逻辑值转换为字符串,并返回结果. 1.2 字符串转数字类型 Num ...

  5. css3 calc()属性介绍以及自适应布局使用方法

    前端知识 Calc()介绍 calc的英文是calculate的缩写,中文为计算的意思,是css3的一个新增的功能,用来只当元素的长度.比如说:你可以用calc()给元素margin.padding. ...

  6. nginx 1.15.10 前端代理转发 将多个地址,代理转发到一个地址和端口 多系统公用一个cookie 统一token

    nginx 1.15.10 前端代理转发 将多个地址,代理转发到一个地址和端口 多系统公用一个cookie 统一token 注意: proxy_pass http://192.168.40.54:22 ...

  7. ubuntu命令行转换图片像素大小

    convert -resize 512x256 00433.png 00001.png 1.512和256之间是x(就是字母那个x),用' * '反而会报错 2.这个命令会按照原图的比例进行转换 3. ...

  8. c++ cpp和hpp

    首先,我们可以将所有东西都放在一个.cpp文件内,编译器会将这个.cpp编译成.obj,即编译单元.一个程序可以由一个编译单元组成,也可以由多个编译单元组成.一个.cpp对应一个.obj,然后将所有的 ...

  9. Vickers Vane Pump - Hydraulic Vane Pump Failure: Cavitation, Mechanical Damage

    One of our readers recently wrote to me about the following questions: “Recently, we purchased a sec ...

  10. 32位和64位系统下 int、char、long、double所占的内存

    32位和64位系统下 int.char.long.double所占内存