Codeforces 1062 E - Company】的更多相关文章

E - Company 思路: 首先,求出每个点的dfs序 然后求一些点的公共lca, 就是求lca(u, v), 其中u是dfs序最大的点, v是dfs序最小的大点 证明: 假设o是这些点的公共lca, in[o]是o的入时间戳, out[o]是o的出时间戳, 那么对于任意一点x, in[o] <= in[v] <= in[x] <= in[u] <= out[o] 所以o是x的祖先 所以o是这些点的公共lca 所以只要求出每段区间的dfs序最大的和最小的, 删除的要么是最大的,…
链接:http://codeforces.com/contest/1062 A - Prank - [二分] 题意: 给出长度为 $n(1 \le n \le 100)$ 的数组 $a[1 \sim n]$,且满足 $1 \le a[1] < a[2] < \cdots < a[n] \le 1000$.现在JATC要擦掉其中一段连续的数字,但是要求能够通过剩余的其他数字,推断出擦掉的数字是什么.求JATC能擦掉的最长长度. 题解: 其实 $O(n)$ 就可以求出能擦掉的最长长度,但是因…
传送门 D. Restructuring Company time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Even the most successful company can go through a crisis period when you have to make a hard decision — to rest…
http://codeforces.com/contest/794/problem/C Description Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little things. Recently, they started a new company, but they are having trouble finding a name for the…
E. MST Company time limit per test 8 seconds memory limit per test 256 megabytes input standard input output standard output The MST (Meaningless State Team) company won another tender for an important state reform in Berland. There are n cities in B…
Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little things. Recently, they started a new company, but they are having trouble finding a name for the company. To settle this problem, they've decided to play…
Restructuring Company Even the most successful company can go through a crisis period when you have to make a hard decision — to restructure, discard and merge departments, fire employees and do other unpleasant stuff. Let's consider the following mo…
题意:给定一个带权边无向图,求最小生成树,且满足第一个节点的度为固定的k 无解则输出-1 数据规模: 节点数n和限制k<=5000 边数m<=10^5 时限8sec 思路: 首先时限比较宽,第一个想到的暴力做法是枚举第一个节点(即首都)选中的K条边,复杂度为阶乘级别 无法接受.但是我们可以确定,问题的关键在于在所有国道中选择哪k条国道.一旦k条国道选定,最小生成树就是固定的. 考虑一个极端的情况,如果我们直接对这个图运行Kruskal算法,得到了一个树 且 第一个节点的度为k,则这就是正确的答…
题意:给定 3 种操作, 第一种 1 u v 把 u 和 v 合并 第二种 2 l r 把 l - r 这一段区间合并 第三种 3 u v 判断 u 和 v 是不是在同一集合中. 析:很容易知道是用并查集来做,但是如果单纯的用并查集,肯定是要超时的,所以要用链表,如果合并了,就把链表指向, 这样就搞定了这个题. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #i…
B. Kefa and Company Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/580/problem/B Description Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company. Kefa has n friends, each friend wi…