PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#LCA0000081. Đếm số hành trình qua từng con đường (Fools and Roads)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đếm số hành trình qua từng con đường (Fools and Roads)
Fools and Roads
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
There are cities connected by bidirectional roads that form a tree. Each of journeys travels along the unique simple path from city to city . For every road, count the journeys that use it. Roads retain their input order.
Input
First line: . Next lines: . Then integer , followed by lines .
Output
Print integers in the same order as the input edges.
Subtasks
-
Subtask 1 (20 points): ; ; ; for every edge; edges form a tree vô hướng.
-
Subtask 2 (30 points): ; ; ; for every edge; edges form a tree vô hướng.
-
Subtask 3 (50 points): ; ; ; for every edge; edges form a tree vô hướng.
Examples
Input
5
1 2
1 3
2 4
2 5
2
1 4
3 5
Output
2 1 1 1
Explanation
Path uses roads ; path uses roads . Road is used twice.