PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#LCA0000100. Kế hoạch vận chuyển (Transportation Plan)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Kế hoạch vận chuyển (Transportation Plan)
Transportation Plan
Source: Luogu
Version: Phuoc Hung OJ Extended
Problem Statement
There are planets connected by bidirectional routes forming a tree. Each route has a nonnegative travel time. There are transportation plans , each following the unique path from to . All plans run concurrently, so the completion time is the maximum duration among the plans.
You may choose one edge and change its travel time to zero for all plans. Find the minimum possible completion time.
Input
- The first line contains .
- The following lines each contain : a bidirectional edge and its travel time.
- The following lines each contain : one transportation plan.
Output
Print one integer: the minimum completion time.
Subtasks
- Subtask 1 (20 points): , ; ; . Các cạnh tạo thành một cây. Additionally, and the number of queries/plans is at most .
- Subtask 2 (30 points): , ; ; . Các cạnh tạo thành một cây. Additionally, and the number of queries/plans is at most .
- Subtask 3 (50 points): , ; ; . Các cạnh tạo thành một cây.
Examples
Input
3 2
1 2 4
2 3 6
1 3
2 3
Output
4
Explanation
Setting the travel time of edge – to zero leaves durations and for the two plans; hence the completion time is . Setting the other edge to zero would leave the first plan at duration .