Codeforces Gym 101630L Laminar Family 树链剖分

Problem L. Laminar Family

Input file: standard input
Output file: standard output
Time limit: 3 seconds
Memory limit: 512 mebibytes

While studying combinatorial optimization, Lucas came across the notion of “laminar set family”. A subset family F of some set Ω is called laminar if and only if it does not contain an empty set and for any two distinct sets A, B ∈ F it is correct that either A ⊂ B or B ⊂ A or A ∩ B = ∅.
As an experienced problem setter Lucas always tries to apply each new piece of knowledge he gets as an idea for a programming competition problem. An area of his scientific interests covers recognition problems that usually sound like “Given some weird combinatorial property, check if the given structure satisfies it”.
Lucas believes that the perfect programming competition problem should contain a cactus a tree in it.
Trying to put together laminar sets and trees into a recognition problem, he finally came up with the following problem: given an undirected tree on n vertices and a family F = {F1, … , Fk} of sets, where Fi consists of all vertices belonging to the simple path between some two vertices ai and bi of the tree, check if the family F is a laminar family. Note that in this case Ω = V , and each Fi ⊆ V .
As you can see, Lucas had succeeded in suggesting this problem to the programming contest. Now it is up to you to solve it.

Input

The first line of the input contains two integers n and f (1 ≤ n, f ≤ 100 000) — the number of vertices in the tree and the number of elements in a family F.
Next n−1 lines describe the tree structure. In the i-th line there are two integers ui and vi (1 ≤ ui, vi ≤ n,ui != vi) — the indices of the vertices that are connected by the i-th edge of the tree.
Next f lines describe the sets forming the family F. In the i-th line there are two integers ai and bi (1 ≤ ai, bi ≤ n), such that Fi consists of all vertices belonging to the simple path between vertices ai and bi in the tree (including ai and bi)

Output

Output the only word “Yes” or “No” depending on whether or not the given set family is laminar.

Sample Input Sample Output
4 2
1 2
2 3
2 4
1 2
4 2
No
6 5
1 2
2 3
3 4
5 6
5 2
2 1
6 6
1 4
3 4
4 1
Yes

给出一棵树的若干路径,判断它们两两间是否都存在包含关系或完全没有交点。

利用树链剖分维护树的点权,依次处理每条链。若链上的max=min则符合题意,将链上所有点权值+1,否则就是No。

处理链之前需要先排序,第一关键字为lca深度,第二关键字为链的长度。


#include <cstdio>
#include <iostream>
#include <string.h>
#include <string> 
#include <map>
#include <queue>
#include <deque>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <stack>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您提供的链接是Codeforces的一个问题,问题编号为104377。Codeforces是一个知名的在线编程竞赛平台,经常举办各种编程比赛和训练。GymCodeforces的一个扩展包,用于组织私人比赛和训练。您提供的链接指向了一个问题的页面,但具体的问题内容和描述无法通过链接获取。如果您有具体的问题或需要了解关于Codeforces Gym的更多信息,请提供更详细的信息。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [http://codeforces.com/gym/100623/attachments E题](https://blog.csdn.net/weixin_30820077/article/details/99723867)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [http://codeforces.com/gym/100623/attachments H题](https://blog.csdn.net/weixin_38166726/article/details/99723856)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [CodeforcesPP:Codeforces扩展包](https://download.csdn.net/download/weixin_42101164/18409501)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值