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个人,同时有每个人的扩张次数(我开始以为是直线扩张最大长度..实际是能连 ...
随机推荐
- Hello Shell
shell是Linux平台的瑞士军刀,能够自动化完成很多工作.要了解UNIX 系统中可用的 Shell,可以使用 cat /etc/shells 命令.使用 chsh 命令 更改为所列出的任何 She ...
- ASP.NET Web API FilterAttribute假想
偶然的测试发现API FilterAttribute没用引用只会初始化一次 比如: 如果是 Global Action Filter, 则全局只会初始化一次 针对于不同的Controller级别的Ac ...
- 【HEVC帧间预测论文】P1.6 A Fast HEVC Inter CU Selection Method Based on Pyramid Motion Divergence
A Fast HEVC Inter CU Selection Method Based on Pyramid Motion Divergence <HEVC标准介绍.HEVC帧间预测论文笔记&g ...
- Selenium私房菜系列2 -- XPath的使用【ZZ】
在编写Selenium案例时,少不免是要用到XPath的,现在外面关于XPath使用的参考资料很多,下面我直接转一篇关于XPath使用的文档.如果对XPath不熟悉请参考下文,你不需要去百度/Goog ...
- 一个简单的139邮箱登录脚本--->java-selenium
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebE ...
- 洛谷 P2053 [SCOI2007]修车
题目描述 同一时刻有N位车主带着他们的爱车来到了汽车维修中心.维修中心共有M位技术人员,不同的技术人员对不同的车进行维修所用的时间是不同的.现在需要安排这M位技术人员所维修的车及顺序,使得顾客平均等待 ...
- 10道有关ios的题
1.你使用过Objective-C的运行时编程(Runtime Programming)么?如果使用过,你用它做了什么?你还能记得你所使用的相关的头文件或者某些方法的名称吗? 2.你实现过多线程的Co ...
- 【整理】解决vue不相关组件之间的数据传递----vuex的学习笔记,解决报错this.$store.commit is not a function
解决vue不相关组件之间的数据传递----vuex的学习笔记,解决报错this.$store.commit is not a function https://www.cnblogs.com/jaso ...
- Python基础1 介绍、基本语法 、 流程控制-DAY1
本节内容 Python介绍 发展史 Python 2 or 3? 安装 Hello World程序 变量 用户输入 模块初识 .pyc是个什么鬼? 数据类型初识 数据运算 表达式if ...else语 ...
- java程序在一个电脑上只启动一次,只开一个进程
方案1: 单进程程序可以用端口绑定.程序启动的时候可以尝试看该端口是否已经被占用,如果占用则程序已经启动. 方案2:你可以在java程序中创建一个隐藏文件,程序退出的时候删除这个文件.这样在程序启动的 ...