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

14033번 - Artskjid 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB55161330.233%

문제

There are many well-known algorithms for finding the shortest route from one location to another. People have GPS devices in their cars and in their phones to show them the fastest way to get where they want to go. While on vacation, however, Troy likes to travel slowly. He would like to take the longest route to his destination so that he can visit many new and interesting places along the way.

As such, a valid route consists of a sequence of distinct cities c1, c2, ..., ck, such that there is a road from ci to ci+1 for each 1 ≤ i < k.

He does not want to visit any city more than once. Can you help him find the longest route?

입력

The first line of input contains two integers n, m, the total number of cities and the number of roads connecting the cities (2 ≤ n ≤ 18; 1 ≤ m ≤ n2 − n). There is at most one road from any given city to any other given city. Cities are numbered from 0 to n − 1, with 0 being Troy’s starting city, and n − 1 being his destination.

The next m lines of input each contain three integers s, d, l. Each triple indicates that there is a one way road from city s to city d of length l km (0 ≤ s ≤ n − 1; 0 ≤ d ≤ n − 1; s ≠ d; 1 ≤ l ≤ 10000). Each road is one-way: it can only be taken from s to d, not vice versa. There is always at least one route from city 0 to city n − 1.

출력

Output a single integer, the length of the longest route that starts in city 0, ends in city n − 1, and does not visit any city more than once. The length is the sum of the lengths of the roads taken along the route.

제한

예제 입력 1

3 3
0 2 5
0 1 4
1 2 3

예제 출력 1

7

The shortest route would be to take the road directly from 0 to 2, of length 5 km. The route going from 0 to 1 to 2 is 4 + 3 = 7 km, which is longer.

힌트

출처

Olympiad > Canadian Computing Competition & Olympiad > 2015 > CCO 2015 2번

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

출처

대학교 대회

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

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