CodeForces 1062E Company】的更多相关文章

Description The company \(X\) has \(n\) employees numbered from \(1\) through \(n\). Each employee \(u\) has a direct boss \(p_u\) \((1 \le p_u \le n)\), except for the employee \(1\) who has no boss. It is guaranteed, that values \(p_i\) form a tree…
题目链接:https://codeforces.com/contest/1090/problem/A A conglomerate consists of n companies. To make managing easier, their owners have decided to merge all companies into one. By law, it is only possible to merge two companies, so the owners plan to s…
给出一棵有根树,1为根结点,接下来q次询问,每次给出一个[l,r]区间,现在允许删掉[l,r]区间内任何一个点,使得所有点的最近公共祖先的深度尽可能大,问删掉的点是哪个点,深度最大是多少. 做法: 线段树维护区间dfs序的最大值,最小值. 首先,区间的LCA等价于区间dfs序的最小值和最大值对应的两个点的LCA. 然后,根据dfs序的性质,当删掉的点的dfs序最大或者最小时,对答案贡献最大. 所以接下来只要去查询区间里的LCA(最小值,次大值),以及LCA(次小值,最大值),两个LCA中深度最大…
题意 描述有点麻烦,就不写了. \(\texttt{Data Range:}1\leq n\leq 500\) 题解 势能函数这个东西好神啊-- 这个题目用常规的 DP 好像做不出来,所以我们可以考虑设计一个函数将一个局面到最终局面的期望进行评估,如果这个函数能够满足任意一次操作会使得函数值的期望增加 \(1\),那么就可以用最终局面的函数值减去初始局面的函数值就得到期望操作次数了. 同时,必须满足最终局面无法转移,因为有环的转移图比较难去算转移,这个时候势能函数就出来了. 这个题目中我们考虑设…
传送门 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…
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…
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…
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序最大的和最小的, 删除的要么是最大的,…
https://codeforces.com/contest/1062/problem/E 题意 给一颗树n,然后q个询问,询问编号l~r的点,假设可以删除一个点,使得他们的最近公共祖先深度最大.每次询问,输出删除的点和祖先的深度 思路 考虑dfs序来判断v是否在u的子树里: dfn[u]<dfn[v]<=max(dfn[u的子树]) 那么进一步拓展,dfs序之差越大,点就在越分离的地方,这些点的lca一定是lca(max(dfn[u]),min(dfn[u])) 这不仅知道了需要去掉哪个点(…