E. 暮雪少年与树

    传统题 4000ms 512MiB

暮雪少年与树

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

Problem Background

After winning the silver medal, the young Muxue enrolled at Peking University. While happily walking on a forest path, he recalled an unsolved problem from the competition.

Problem Description

Young Muxue has a tree with nn vertices and a complete graph with nn vertices. Both the tree and the graph have edge weights, and every natural number less than n1n-1 appears exactly once among the edge weights of the tree. The length of an edge uvu \to v in the complete graph is defined as the mex\operatorname{mex} of the edge weights along the unique simple path from uu to vv in the tree.
You are given the tree, and you need to tell Muxue the total weights of the minimum spanning tree and the maximum spanning tree of his complete graph.

Input Format

The first line contains an integer nn.
The next n1n-1 lines each contain three non-negative integers ui,vi,wiu_i, v_i, w_i, representing an edge in the tree.

Output Format

Output one line with two integers: the total weight of the minimum spanning tree and the total weight of the maximum spanning tree.

Sample Input/Output 1

Input

5
1 2 0
1 3 1
1 4 2
1 5 3

Output

1 5

Constraints

For all test data, it is guaranteed that:1ui,vin2×1061 \le u_i, v_i \le n \le 2\times 10^6, 0wi<n10 \le w_i < n-1, ijn,wiwj\forall i \neq j \le n, w_i \neq w_j.

【XJS-C5-Div1】XJSOI 春节大月赛 Round 3 & 勰码可达鸭合作赛 Round 1

未参加
状态
已结束
规则
IOI
题目
5
开始于
2026-2-17 0:00
结束于
2026-2-24 0:00
持续时间
168 小时
主持人
参赛人数
5