input The first line of the input contains two natural numbers n n number of company…
- User
input The first line of the input contains two natural numbers n n number of company employees and m m is the number of parties that can be held by the company.
The second line includes n
1 n−1 natural number p 2 , p 3 , ⋯ , p n p 2 ,p 3 , ⋯, p n is so that p i p i The representative of the employee no i i is
in each of m m next line three natural numbers in order u u v v and c c is said to represent a party of three ( u , v , c ) (u,v,c) is The individual is guaranteed v v Senior u u is 1 ≤ n ≤ 100
000 1≤n≤100 000
1 ≤ m ≤ 300
000 1≤m≤300 000
1 ≤ p i < i 1≤p i <i
u ≠ v , 1 ≤ u , v ≤ n u =v,1≤u,v≤n
1 ≤ c ≤ 1 0 9 1≤c≤10 9
output In the only output line, print the lowest cost to achieve the company's request.
Sub-issues Constraint score subproblem 1 6 n ≤ 100 n≤100, m ≤ 100 m ≤ 100 2 8 m ≤ 3
000 m≤3 000, n ≤ 3
000 n≤3 000 3 15 n ≤ 3
000 n≤3 000 4 14 p i
i
1 p i =i−1 5 52 without additional restrictions Example Sample entry 1 4 3 1 2 2 3 1 10 4 1 20 4 2 15 Plain text Sample output 1 25
- Assistant
To solve this problem, we need to approach it like a minimum spanning tree (MST) problem with considerations on a hierarchy or tree-like structure defined by the
n-1natural numbers in the input, which are essentially parent-child relationships among employees.