아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Bus Lines

시간 제한0.75초메모리 제한64 MB

요약
각 간선에 용량이 있는 트리에서, 각 간선을 용량 이하로만 사용하면서 서로 다른 두 잎을 잇는 경로의 최대 개수를 구한다.
난이도

보통10점 중 7점

유형
트리, 그리디, DFS, 동적 계획법
정답자
아직 제출이 없습니다

문제

There are (n−1)(n - 1) bidirectional streets connecting nn crossroads (numbered 11 to nn) in Byteozavodsk. There is only one way to travel between every pair of crossroads without going through any street more than once.

You are tasked with planning city's bus line routes. A bus line route starts and ends at a crossroad such that there is only one street that is incident with this crossroad. The starting crossroad must be different from the ending one.

Every street has a capacity: the number of bus lines that can pass through this street.

Calculate the maximum possible number of bus lines that can be arranged in Byteozavodsk. Not that it makes any sense, but there can be two bus lines that are connecting exactly the same pair of crossroads.

입력

The first line contains one integer zz, the number of test cases. Then zz test cases are described in the following way.

The first line of each test case description contains one integer nn (2≤n≤1052 \leq n \leq 10^5), the number of crossroads in Byteozavodsk. Each of the following (n−1)(n - 1) lines describing city streets contains three integers aa, bb, cc (1≤a,b≤n1 \leq a, b \leq n, a≠ba \neq b, 1≤c≤1061 \leq c \leq 10^6) meaning that a particular street connects crossroad aa with crossroad bb, and has a capacity of cc.

출력

For each test case, output a single line containing one integer: the maximum number of bus lines that can be arranged in Byteozavodsk.

예제1

  1. 예제 1

    입력
    3
    4
    1 2 2
    1 3 2
    1 4 2
    2
    1 2 2
    3
    1 2 2
    2 3 1
    
    예상 출력
    3
    2
    1