本文章施工中……
进度[===> ] 2/10 20%
A. Alternative Accounts
题目描述
Everybody knows that jiry_2 = Syloviaely.
There are $n$ different accounts on the website, and some of them competed in the recent $k$ contests. However, Mike suspects that there are lots of alternative accounts.
There are axioms believed by everyone that nobody can use two different in one contest simultaneously and each account can be owned by only one person. So different accounts without overlapping contest participation can be owned by the same person.
Mike wants to know the minimum possible number of different people behind these accounts.
题目分析
题目意思就是给三个相交的完全图,求最少染色数。
考虑一下,$A\cap B\cap C,(A\cap B)-C,(A\cap C)-B,(B\cap C)-A$都是需要染不同颜色的,否则由于两两处于完全图中,必定会染色失败。
而$A-B-C$与$B\cap C-A$是可以染相同颜色的,同理其他两种情况一样。
故答案就是:
代码
1 |
|
B. Bitset Master
题目描述
It’s well known in China that $O(n^2)$ algorithms can pass the problem with $n=10^6$ easily.
You are given a tree with $n$ vertices and $n-1$ edges $(u_1, v_1), (u_2, v_2), \dots, (u_{n-1},v_{n-1})$
For each vertex $u$,there is a set $S_u=\{u\}$ initially.
You need to perform $m$ operations. For the $i$-th operation, you are given an edge $p_i$ and let $S_{u_{p_i}}$ and $S_{v_{p_i}}$ be the union of them.
Finally, you need to find the number of sets $S(v)$ contains $u$ for each vertex $u$.
题目分析
将包含$v$的集合看做,$v$能到达的集合。
由于后合并的集合可以使前面的点到达,但先合并的集合不能使后面的点到达,故倒过来考虑,维护每个集合的大小即可统计出每个点可以到达多少个集合。
如何快速维护集合大小?
而$\left|S_u\cap S_v\right|$的大小就是上一次的$S_u,S_v$合并后的大小。
代码
1 |
|