知识点

最大独立集(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
  1. 5 3
  2. 1
  3. 2 motarack
  4. 2 mike
  5. 1
  6. 2 light
output

Copy
  1. 2
input

Copy
  1. 4 3
  2. 1
  3. 2 alice
  4. 2 bob
  5. 2 tanyaromanova
output

Copy
  1. 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代码

  1. #include <bits/stdc++.h>
  2. #define pb push_back
  3. #define mp make_pair
  4. #define fi first
  5. #define se second
  6. #define all(a) (a).begin(), (a).end()
  7. #define fillchar(a, x) memset(a, x, sizeof(a))
  8. #define huan printf("\n")
  9. #define debug(a,b) cout<<a<<" "<<b<<" "<<endl
  10. #define ffread(a) fastIO::read(a)
  11. using namespace std;
  12. const int maxn = 1e5+;
  13. const int maxm = 1e4+;
  14. const int inf = 0x3f3f3f3f;
  15. const int mod = ;
  16. const double epx = 1e-;
  17. typedef long long ll;
  18. const ll INF = 1e18;
  19. const double pi = acos(-1.0);
  20. //head------------------------------------------------------------------
  21. int G[][];
  22. int ans,cnt[],group[],n,m,vis[];//ans表示最大团,cnt[N]表示当前最大团的节点数,group[N]用以寻找一个最大团集合
  23. map<string,int> pm;
  24. int tot = ;
  25. struct node
  26. {
  27. int op;
  28. string s;
  29. } Q[maxn];
  30. vector<int> v;
  31. bool dfs(int u,int pos)//u为当从前顶点开始深搜,pos为深搜深度(即当前深搜树所在第几层的位置)
  32. {
  33. int i,j;
  34. for(i=u+; i<=tot; i++) //按递增顺序枚举顶点
  35. {
  36. if(cnt[i]+pos<=ans)
  37. return ;//剪枝
  38. if(G[u][i])
  39. {
  40. // 与目前团中元素比较,取 Non-N(i)
  41. for(j=; j<pos; j++)
  42. if(!G[i][vis[j]])
  43. break;
  44. if(j==pos)
  45. {
  46. // 若为空,则皆与 i 相邻,则此时将i加入到 最大团中
  47. vis[pos]=i;//深搜层次也就是最大团的顶点数目,vis[pos] = i表示当前第pos小的最大团元素为i(因为是按增顺序枚举顶点 )
  48. if(dfs(i,pos+))
  49. return ;
  50. }
  51. }
  52. }
  53. if(pos>ans)
  54. {
  55. for(i=; i<pos; i++)
  56. group[i] = vis[i]; // 更新最大团元素
  57. ans = pos;
  58. return ;
  59. }
  60. return ;
  61. }
  62. void maxclique()//求最大团
  63. {
  64. ans=-;
  65. for(int i=tot; i>; i--)
  66. {
  67. vis[]=i;
  68. dfs(i,);
  69. cnt[i]=ans;
  70. }
  71. }
  72. int main()
  73. {
  74. scanf("%d%d",&n,&m);
  75. for(int i=; i<=n; i++)
  76. {
  77. int op;
  78. string tmp;
  79. scanf("%d",&op);
  80. if(op==)
  81. Q[i].op = op;
  82. else
  83. {
  84. cin>>tmp;
  85. Q[i].op = op;
  86. Q[i].s = tmp;
  87. if(!pm[tmp])
  88. pm[tmp] = ++tot;
  89. }
  90. }
  91. memset(G,inf,sizeof(G));
  92. Q[n+].op=;
  93. for(int i=; i<=n+; i++)
  94. {
  95. if(Q[i].op==)
  96. {
  97. for(int j=; j<v.size(); j++)
  98. {
  99. for(int k=j+; k<v.size(); k++)
  100. {
  101. G[v[k]][v[j]] = ;
  102. G[v[j]][v[k]] = ;
  103. }
  104. }
  105. v.clear();
  106. }
  107. else
  108. {
  109. v.push_back(pm[Q[i].s]);
  110. }
  111. }
  112. maxclique();
  113. if(ans<)
  114. ans = ;
  115. printf("%d\n",ans);
  116. return ;
  117. }

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. COGS 2274. [HEOI 2016] tree

    ★☆   输入文件:heoi2016_tree.in   输出文件:heoi2016_tree.out   简单对比时间限制:1 s   内存限制:128 MB 这道题数据弱到炸了 . 第一次做用树刨 ...

  2. c++ vector容器遍历方式

    #include <vector> #include <iostream> class Test { public: int a; int b; int c; Test() { ...

  3. pm2 start命令中的json格式详解

    pm2 start npm -- start这条命令是pm2的万能命令,pm2 start <json>,就是这一系列命令中的最豪华命令.这个json我们可以理解为一个任务参数描述文件.通 ...

  4. [题解] cogs 1669 神秘的咒语

    http://cogs.pro:8080/cogs/problem/problem.php?pid=1669 "The Real Incantation is Their Common In ...

  5. InnoDB INFORMATION_SCHEMA Metrics Table

    InnoDB INFORMATION_SCHEMA Metrics Table INNODB_METRICS表将所有InnoDB性能和资源相关计数器合并到一个INFORMATION_SCHEMA表中. ...

  6. 文本三剑客之sed

    sed是一个流编辑器(sed是stream editor的缩写),它可以对从标准输入流中得到的数据进行处理,然后把处理以后得到的结果输出到标准输出,而标准输出通常会关联到终端屏幕,因此处理后的结果也会 ...

  7. 条款26:尽可能延后变量定义式的出现时间(Postpone variable definitions as long as possible)

    NOTE : 1.尽可能延后变量定义式的出现时间.这样做可增加程序的清晰度并改善程序效率.

  8. 【转】Unable to load native-hadoop library for your platform(已解决)

    1.增加调试信息寻找问题 2.两种方式解决unable to load native-hadoop library for you platform 附:libc/glibc/glib简介 参考: 1 ...

  9. 第二天,学习if,变量,注释

    zz_age = 31guss_age=int(input("input your answer:"))if guss_age == zz_age: print ("Yo ...

  10. SCI journals on Energy

    SCI journals on Energy Table of Contents 1. SCI- Clarivate - Thomson Reuters 1 SCI- Clarivate - Thom ...