CF708C.Centroids

提高+/省选-

通过率:0%

时间限制:4.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Tree is a connected acyclic graph. Suppose you are given a tree consisting of n vertices. The vertex of this tree is called centroid if the size of each connected component that appears if this vertex is removed from the tree doesn't exceed .

You are given a tree of size n and can perform no more than one edge replacement. Edge replacement is the operation of removing one edge from the tree (without deleting incident vertices) and inserting one new edge (without adding new vertices) in such a way that the graph remains a tree. For each vertex you have to determine if it's possible to make it centroid by performing no more than one edge replacement.

树是连通的无环图。假设你被给定一棵包含 nn 个顶点的树。若从该树中删除某个顶点后,所产生的每个连通分量的大小均不超过 ,则称该顶点为重心(centroid)。

你被给定一棵大小为 nn 的树,并且最多可执行一次边替换操作。边替换操作指:从树中移除一条边(不删除其关联的顶点),再插入一条新边(不添加新顶点),使得所得图仍为一棵树。对于每个顶点,你需要判断:是否可通过至多一次边替换操作,使其成为该树的重心。

输入格式

The first line of the input contains an integer n (2 ≤ n ≤ 400 000) — the number of vertices in the tree. Each of the next n - 1 lines contains a pair of vertex indices u__i and v__i (1 ≤ u__i, v__i ≤ n) — endpoints of the corresponding edge.

输入的第一行包含一个整数 nn(2≤n≤400 0002 \leq n \leq 400\,000)——树中顶点的数量。接下来的 n−1n-1 行,每行包含一对顶点编号 uiu_i 和 viv_i(1≤ui, vi≤n1 \leq u_i,\, v_i \leq n)——对应边的两个端点。

输出格式

Print n integers. The i-th of them should be equal to 1 if the i-th vertex can be made centroid by replacing no more than one edge, and should be equal to 0 otherwise.

输出 nn 个整数。其中第 ii 个整数应为 1,当且仅当通过至多替换一条边,可使第 ii 个顶点成为树的重心;否则应为 0。

输入输出样例

  • 输入#1

    3
    1 2
    2 3

    输出#1

    1 1 1
  • 输入#2

    5
    1 2
    1 3
    1 4
    1 5

    输出#2

    1 0 0 0 0

说明/提示

In the first sample each vertex can be made a centroid. For example, in order to turn vertex 1 to centroid one have to replace the edge (2, 3) with the edge (1, 3).

在第一个样例中,每个顶点都可以成为重心。例如,要使顶点 1 成为重心,需将边 (2, 3)(2, 3) 替换为边 (1, 3)(1, 3)。

输入解题思路,AI测评打分。不知道怎么写?

首页