AtCoder Beginner Contest 240 E

题面
Problem Statement
You are given a rooted tree with N vertices. The root is Vertex 1.
For each i=1,2,…,N−1, the i-th edge connects Vertex ui and Vertex vi .
For each i=1,2,…,N, let Si denote the set of all vertices in the subtree rooted at Vertex i. (Each vertex is in the subtree rooted at itself, that is, i∈Si .)
Additionally, for integers l and r, let [l,r] denote the set of all integers between l and r, that is, [l,r]={l,l+1,l+2,…,r}.
Consider a sequence of N pairs of integers ((L1​ ,R1​),(L2 ,R2),…,(LN ,RN)) that satisfies the conditions below.1≤Li≤Ri for every integer i such that 1≤i≤N.
The following holds for every pair of integers (i,j) such that 1≤i,j≤N.[Li,R i]⊆[L j,R j] if Si⊆Sj [Li,Ri]∩[Lj ,Rj]=∅ if S i∩S j=∅
It can be shown that there is at least one sequence ((L1,R 1),(L 2,R 2 ),…,(LN​,RN)). Among those sequences, print one that minimizes max{L1,L2,…,LN,R1 ,R2,…,RN}, the maximum integer used. (If there are multiple such sequences, you may print any of them.)
Constraints
2≤N≤2×10^5
1≤ui ,vi≤N
All values in input are integers.
The given graph is a tree.
大意
已知一个有N个顶点的有根树。根结点是顶点1。
对于每个i=1,2,…,N−1,第i条边连接顶点ui和顶点vi。
对于每个i=1,2,…,N,设Si表示以顶点i为根的子树中所有顶点的集合(每个顶点都在以自身为根的子树中,即i∈Si)。
另外,对于整数l和r,设[l,r]表示l和r之间的所有整数的集合,即[l,r]={l,l+1,l+2,…,r}。
考虑一个N对整数序列((L1,R1),(L2,R2),…,(LN,RN))满足下列条件。1≤Li≤Ri对于每个整数i,使1≤i≤N。
下面的式子适用于每一对整数(i,j),使1≤i,j≤N。(李,R)⊆(L j R j]如果Si⊆Sj (Li Ri)∩(Lj, Rj) =∅if S i∩S j =∅
结果表明,至少存在一个序列((L1, r1),(l2, r2),…,(LN,RN))。在这些序列中,打印一个使所使用的最大整数max{L1,L2,…,LN,R1,R2,…,RN}最小的序列。(如果有多个这样的序列,您可以打印其中的任何一个。)
调格式与翻译用了很长时间,累死我了qwq

看似很麻烦,可我们可以理一理
1,对于每个i=1,2,…,N−1,第i条边连接顶点ui和顶点vi。
2,对于每个i=1,2,…,N,设Si表示以顶点i为根的子树中所有顶点的集合(每个顶点都在以自身为根的子树中,即i∈Si)。
3,对于整数l和r,设[l,r]表示l和r之间的所有整数的集合,即[l,r]={l,l+1,l+2,…,r}。
4,适用于每一对整数(i,j),使1≤i,j≤N。(李,R)⊆(L j R j]如果Si⊆Sj (Li Ri)∩(Lj, Rj) =∅if S i∩S j =∅
5,至少存在一个序列((L1, r1),(l2, r2),…,(LN,RN))。在这些序列中,打印一个使所使用的最大整数max{L1,L2,…,LN,R1,R2,…,RN}最小的序列。

这样就一目了然了,这题仍要用到pair。
然后我调用了一个atcoder的头#include <atcoder/all>
这是solve函数

pair<int, int> solve(int cur, int prev){
   
    int count = 0;
    for (int next : to[cur])
    {
   
        if (next != prev)
        {
   
            count++;
        }
    }
    if (count == 0)
    
  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值