루미 알고리즘

#1295골드Jan Ersa

PO 2009 온라인 예선코딩영어 원문이 문제가 어렵다면 — 배우는 순서 보기

영어 원문입니다. 원문의 수식·표를 글자로 옮겨 모양이 다를 수 있습니다. 정확한 내용은 원문 페이지에서 확인하세요. 원문 페이지 열기 (새 창)

Problem

This is how a poem by Gustaf Fröding begins: Jan Ersa ägde Nackabyn, Per Persa ägde Backabyn i By i Västra Ed. Jan Ersa, Per Persa, de höllo aldrig fred.

When Jan Ersa and Per Persa, in their old age, moved into the city, they made sure to end up as far away from each other as possible. Write a program that reads information about the streets in the city and then determines between which two houses the shortest path is the longest, and then outputs the houses and the length of this path. All streets are bidirectional.

(그림은 원문 저장소에서 볼 수 있습니다)

Figure 1: The map shows all houses and streets of the city in the example. We also see the red houses where Jan Ersa and Per Persa now live. These two houses (numbers 1 and 9) are the houses in the city that are farthest away from each other (4900 meters).

Input

The first line contains the integer N (2 ≤ N ≤ 700), the number of houses in the city. The houses are numbered from 1 to N.

The second line contains the integer V (1 ≤ V ≤ 2000), the number of streets.

The following V lines each contain the integers a, b, l (1 ≤ a,b ≤ N, a ≠ b, 1 ≤ l ≤ 100), describing that there is a street between houses a and b with length l (given in hundreds of meters). There is at most one street between each pair of houses. It is guaranteed that it is possible to get from any house to any other house.

Output

Print three integers on one line: the numbers of the two houses farthest away from each other, and the distance between them in meters. If there are several pairs of houses at this distance, you may output any of them.

Scoring

Your solution will be tested on a set of test groups. To earn points for a group, you must pass all test cases in that group.

GroupPointsConstraints
130N ≤ 25, V ≤ 75
270No additional constraints.

예제

예제 1

입력
15
27
1 12 10
1 2 9
2 12 9
6 12 9
3 6 9
2 3 8
3 12 10
3 4 8
4 13 6
5 13 11
5 6 8
4 6 11
4 5 15
6 7 12
7 8 8
8 11 6
9 11 11
9 10 8
7 10 10
10 11 14
8 15 11
5 15 9
5 7 13
5 8 12
5 14 12
13 14 16
14 15 8
출력
1 9 4900

출처 표기

출처: Programmeringsolympiaden 2009년 온라인 예선 · 원문 페이지 · 이용 조건 CC BY-SA · LaTeX 원문을 화면용 글로 옮겼습니다(수식·표의 모양이 다를 수 있습니다). 내용은 고치지 않았습니다.

크리에이티브 커먼즈 저작자표시-동일조건변경허락.

문제 출처: 한국정보올림피아드(KOI) (CC BY-NC-SA 4.0) · International Olympiad in Informatics (IOI) (CC BY) · Centre for Education in Mathematics and Computing (CEMC), University of Waterloo (CC BY-NC 4.0) · Programmeringsolympiaden (CC BY-SA) · CSES Problem Set (Antti Laaksonen) (CC BY-NC-SA 4.0). 루미 알고리즘은 위 단체들과 관계없는 별도의 서비스이며, 자료는 원문 그대로 싣습니다. 문제마다 출처와 이용 조건을 따로 표기합니다.