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

29989번 - Detour 다국어

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

문제

In the city of Nlogonia, the mayor is taking action on his promises to revitalize the city’s road infrastructure. However, the road renewal process renders certain roads temporarily impassable, requiring the establishment of detours to ensure uninterrupted traffic flow.

Each road segment connects two crossroads in the city, has a positive length and can be traversed in both directions. A detour is a designated alternative route that temporarily replaces a road segment under renewal. Specifically, when the road connecting crossroads U and V is impassable, the detour must be a sequence of roads that originates at U and terminates at V , while intentionally avoiding the direct road between U and V . The goal is to find the shortest detour for each road segment to minimize disruptions while road improvements take place.

As the Intern at the Center for Pavement and Cars, your responsibility is to support the mayor’s initiative by calculating the length of the shortest detour for each road segment within the city.

입력

The first line contains two integers, N and M (1 ≤ N ≤ 300), representing the number of crossroads in the city and the number of road segments. Each of the following M lines contains three integers, U, V , and L (1 ≤ U ≤ N, 1 ≤ V ≤ N, U ≠ V , 1 ≤ L ≤ 106), representing a two-way road segment of length L that connects crossroads U and V. No road segment is duplicated.

출력

Output M lines, each line containing an integer. The integer on the i-th line represents the shortest detour length for the i-th road segment or -1 if there is no possible detour. The answer for each road segment should be given in the same order as road segments are described in the input.

제한

예제 입력 1

4 5
1 2 4
1 3 8
2 3 4
4 1 2
3 4 3

예제 출력 1

9
5
9
11
10

예제 입력 2

2 1
1 2 1

예제 출력 2

-1

힌트

출처

ICPC > Regionals > Latin America > Sub-Regional Brasil do ACM ICPC > Maratona de Programação da SBC 2023 D번

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

출처

대학교 대회

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

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