RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
문제 COCI00729

Stablo II

설명

Patrik received a tree with \(n\) vertices. He decided to paint the edges of that tree
using \(k\) different colors.
Initially, all edges of the tree are painted with color 0. He will use the colors in
order from the first to the \(k\)-th, where he will use the \(i\)-th color to paint all the
edges on the shortest path from the \(x_{i}-th\) to the \(y_{i}-th\) node. If an edge on that
path is already painted, the new color will overwrite the old one.
Help Patrik determine the final color of each edge.

제약

Subtask 1 (15 points): \(u_{i} = i\), \(v_{i} = i + 1\) za svaki \(i\)

Subtask 2 (15 points): n, \(k \le 2000\)

Subtask 3 (45 points): \(n \le 10^{5}\)

Subtask 4 (45 points): No additional constraints.

입력 형식

In the first line of input, there are numbers \(n\) and \(k\) (\(2 \le n \le 10^{6}\), \(1 \le k \le 10^{6}\)), representing the number
of vertices in the tree and the number of colors.
In the next \(n - 1\) lines, there are numbers \(u_{i}\) and \(v_{i}\) (\(1 \le u_{i}\), \(v_{i} \le n\)) — the \(i\)-th edge connects the vertices
\(u_{i}\) and \(v_{i}\). It is guaranteed that the edges form a tree.
In the following \(k\) lines, there are numbers \(x_{i}\) and \(y_{i}\) (\(1 \le x_{i}\), \(y_{i} \le n\)), representing the nodes between
which Patrik paints the edges.

출력 형식

In a single line, print the final color of each edge in the order they were given in the input.

예제 1
입력
6 2
1 2
2 3
2 4
1 5
4 6
5 2
6 1
출력
2 0 2 1 2
예제 2
입력
5 4
1 2
2 3
3 4
4 5
5 5
4 3
2 1
2 4
출력
3 4 4 0
예제 3
입력
5 4
3 5
2 3
4 3
5 1
4 1
5 5
4 2
1 5
출력
1 3 3 4
설명

Clarification of the first example:
With the first color, he painted edges 1 and 4, and then with the second color, he painted edges 1, 3, and
5.

문제 정보

생성자가 기록되지 않았습니다.

출처 COCI 2024/2025 Contest 5

평가 및 의견

Stablo II

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Stablo II

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8