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

30126번 - Trip Compulsion 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
24 초 (추가 시간 없음) 1024 MB21150.000%

문제

Being a very quirky person, you've modeled your large neighbourhood as a set of numbered junctions and two-way roads connecting these junctions. Somewhat disturbingly, you've actually measured the length of each road in nanometers! Whenever you take a trip from one junction to another, you always note down the lengths of the longest road and the shortest road in your trip and then compute the difference between the two. One day, before you set out on a trip, you're overwhelmed by a strong desire to find out what the lowest possible difference is among all trips that have the same starting and ending junction as yours. Of course, computing all this on paper will take you ages and your trip is a little urgent (you must leave in the next 5 hours), so you decide to write a program.

입력

The first line contains T, the number of test cases. The first line of each test case contains two space separated numbers - N (the number of junctions) and R (the number of roads). The second line of each test case contains the two space separated numbers - start (the starting junction of your trip) and end (the ending junction of your trip). Each of the next R lines contains three space separated numbers - from (the starting junction of a road), to (the ending junction of a road) and length (the length of the two-way road connecting from and to).

출력

For each test case, output a single line containing one integer - the lowest possible difference. If no trip is possible between start and end, output a single line saying "NO PATH" (quotes for clarity).

제한

  • 1 ≤ T ≤ 10
  • 2 ≤ N ≤ 2000
  • 0 ≤ R ≤ 3000
  • 0 ≤ start, end, from, to < N
  • 1 ≤ length ≤ 2,000,000,000
  • start and end will be different.

예제 입력 1

3
3 2
0 2
0 1 1000
1 2 5000
2 1
0 1
0 1 1000
2 0
0 1

예제 출력 1

4000
0
NO PATH

힌트

출처

ICPC > Regionals > Asia West Continent > India > The 2009 ACM-ICPC Asia Amritapuri Regional Contest E번

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

출처

대학교 대회

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

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