RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
ICPC00062

F. Longest Rivers

Unrated 레이팅 미적용
난이도
10s
시간 제한
1024MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

The Chao Phraya River System. Picture from Wikimedia Commons. The Chao Phraya River System is the main river system of Thailand. Its six longest rivers listed by decreasing length are: 1. Tha Chin (765 km) 2. Nan (740 km) 3. Yom (700 km) 4. Ping (658 km) 5. Pa Sak (513 km) 6. Wang (335 km) A simplified model of this river system is shown in Figure F.1, where the smaller red numbers indicate the lengths of various sections of each river. The point where two or more rivers meet as they flow downstream is called a confluence. Confluences are labeled with the larger black numbers. In this model, each river either ends at a confluence or flows into the sea, which is labeled with the special confluence number 0. When two or more rivers meet at a confluence (other than confluence 0), the resulting merged river takes the name of one of those rivers. For example, the Ping and the Wang meet at confluence 1 with the resulting merged river retaining the name Ping. With this naming, the Ping has length 658 km while the Wang is only 335 km. If instead the merged river had been named Wang, then the length of the Wang would be 688 km while the length of the Ping would be only 305 km. Tha Chin Ping Wang Pa Sak Yom ^{Nan} 305 335 513 353 765 675 700 Figure F.1: The river system in Sample Input 1. Sa\(me-co\)lored edges indicate a river. The raised awareness of this phenomenon causes bitter rivalries among the towns along the rivers. For example, the townspeople along the Wang protest that maybe with a proper naming scheme, their river could actually be the longest, or maybe the second longest (or at least not last!). To end all the guessing, your task is to validate all such claims. The rank of a river is its position in a list of all rivers ordered by decreasing length, where the best rank is 1 for the longest river. For each river, determine its best possible rank over all naming schemes. At any confluence, the name of a new, larger river in any naming scheme must be one of the names of the smaller rivers which join at that confluence. If two or more rivers have equal lengths in a naming scheme, all the tied rivers are considered to have the best possible ranking. For example, if one river is the longest and all other rivers are equal, those rivers all have rank 2.

제약
입력 형식

The first line of input contains two integers \(n\) (\(1 \le n \le 500\,000\)), which is the number of river sources in the system, and \(m\) (\(0 \le m \le n - 1\)), which is the number of confluences with positive labels. These confluences are numbered from 1 to \(m\). The next \(n\) lines describe the rivers. Each of these lines consists of a string, which is the name of the river at the source, and two integers \(c\) (\(0 \le c \le m\)) and \(d\) (\(1 \le d \le 10^{9}\)), where \(c\) is the identifier of the nearest confluence downstream, and \(d\) is the distance from the source to that confluence in kilometers. River names use only lowercase and uppercase letters a–z, and consist of between 1 and 10 characters, inclusive. The final \(m\) lines describe confluences 1 to \(m\) in a similar fashion. The \(k^{th}\) of these lines describes the confluence with identifier \(k\) and contains two integers: the identifier of the nearest confluence do\(wn- st\)ream and the distance from confluence \(k\) to this confluence in kilometers. It is guaranteed that each confluence 1 through \(m\) appears as “the nearest downstream” at least twice, confluence 0 appears at least once, and all sources are connected to confluence 0.

출력 형식

Display one river per line in the same order as in the input. On that line, display the name of the river and its best possible rank.

예제 1
입력
6 2
PaSak 0 513
Nan 2 675
Yom 2 700
Wang 1 335
Ping 1 305
ThaChin 0 765
0 353
0 65
출력
PaSak 5
Nan 2
Yom 1
Wang 3
Ping 4
ThaChin 1
문제 정보

생성자가 기록되지 않았습니다.

출처 ICPC World Finals 2016

평가 및 의견

F. Longest Rivers

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

F. Longest Rivers

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8