Factor-Full Tree
Time limit1sMemory limit1024 MB
Given a rooted tree of up to 60 vertices, assign each vertex a number up to 10^18 so that x_v divides x_u exactly when v is an ancestor of u.
- Level
Hard8 of 10
- Topics
- Number theory, Tree, DFS
- Solved
- No attempts yet
Problem
Aivar is very good at number theory. In fact, it is the only thing he is good at, but this does not stop him from achieving great things. However, if Aivar wants to solve any problem in life, he first needs to convert it to number theory.
For example, consider a rooted tree with vertices. To work with such structures, Aivar first constructs a divisor labelling of the tree. A divisor labelling assigns each vertex a positive integer so that is an ancestor of if and only if divides .
After constructing such a labelling, Aivar can forget about the tree and consider only the list of numbers .
You are given a rooted tree with vertices. Find a divisor labelling. The vertices are numbered from to , and vertex is the root.
Input
The first line contains an integer ().
Each of the following lines contains two integers and (, ), meaning that an edge connects vertices and . These edges form a tree.
Output
Print one line with integers . These numbers must satisfy . It has been shown that under these constraints, an answer always exists.