#SRD0000134. Các đường đi rời đỉnh trên cây (You Are Given a Tree)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Các đường đi rời đỉnh trên cây (You Are Given a Tree)
You Are Given a Tree
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You are given an undirected tree of vertices labeled through . A simple path never repeats a vertex. In this problem, the length of a path is its number of vertices, not its number of edges.
A set of paths is valid for if every path contains exactly vertices and no vertex belongs to more than one selected path, including path endpoints. Some vertices may remain unused.
For each , find the maximum possible number of paths in a valid set for .
Input
- The first line contains integer , the number of vertices.
- Each of the next lines contains integers describing an undirected edge of the tree.
Output
Print exactly space-separated integers in one line, in increasing order of . The -th integer is the largest number of vertex-disjoint paths, each containing exactly vertices.
Subtasks
- Subtask 1 (10 points): ; the graph is an undirected connected acyclic graph with vertices and exactly edges; on each edge and .
- Subtask 2 (20 points): ; the graph is an undirected connected acyclic graph with vertices and exactly edges; on each edge and .
- Subtask 3 (30 points): ; the graph is an undirected connected acyclic graph with vertices and exactly edges; on each edge and .
- Subtask 4 (40 points): ; the graph is an undirected connected acyclic graph with vertices and exactly edges; on each edge and .
Examples
Example 1
Input
7
1 2
2 3
3 4
4 5
5 6
6 7
Output
7 3 2 1 1 1 1
Explanation
The tree is a chain with seven vertices. For we can select seven one-vertex paths. For , choose , , ; a fourth would need eight vertices. For , choose and . For every , at most one path fits and at least one path of that length exists.
Example 2
Input
6
1 2
2 3
2 4
1 5
5 6
Output
6 2 2 1 1 0
Explanation
For , all six vertices can be selected. For , use paths and ; no three disjoint two-vertex paths exist. For , paths and are disjoint. The longest simple path contains five vertices, for example , so the answer for is zero.