Logo
(追記) (追記ここまで)

34655번 - Halcyon 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
10 초 1024 MB71281630.769%

문제

Minseok and Martin have two weighted trees $T_1, T_2$. They share the same vertex set of size $n,ドル where we index each vertex with integers from 1,ドル 2, \ldots, n$.

For a given $k,ドル Minseok selects $k$ edges from $T_1,ドル and Martin selects $n-1-k$ edges from $T_2$. The union of their selected edges should form a tree. If this is possible, they should minimize the total weight of selected edges.

입력

In the first line, a single integer $N$ denoting the number of vertices in both trees is given.

In the next $N-1$ lines, description of the first tree is given. Each of the $N-1$ lines contains three integers $S_i, E_i, W_i,ドル which indicates there is an edge connecting two vertices $S_i, E_i$ with weight $W_i$.

In the next $N-1$ lines, description of the second tree is given in the same format.

출력

For all 0ドル \le k \le n - 1,ドル print the minimum total weight, or print -1 if it is impossible.

제한

  • 2ドル \le N \le 250,000円$
  • 1ドル \le S_i, E_i \le N, 1 \le W_i \le 10^9$ (1ドル \le i \le N-1$)

예제 입력 1

5
1 2 10
2 4 20
3 4 30
4 5 50
1 2 15
1 3 25
1 4 35
1 5 25

예제 출력 1

100
85
80
85
110

예제 입력 2

9
5 7 6577
4 5 8869
5 9 9088
2 1 124
6 2 410
2 8 8154
4 8 4810
3 4 4268
3 9 763
6 2 8959
7 4 7984
3 8 504
8 6 9085
5 2 4861
1 9 8539
1 7 7834

예제 출력 2

48529
39568
31019
26748
25491
25661
29669
33975
42300

노트

출처

University > KAIST > KAIST ICPC Mock Competition > 2025 KAIST 15th ICPC Mock Competition H번

University > MIT > The MIT Programming Contest > 2025-26 > MIT Team Contest 2 H번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /