포럼
문제 ICPC00316

H. Harry the Hamster

설명

-3mm

-10mm

Harry the Hamster lives in a giant hamster cage. Inside the cage there is a set of \(n\) plastic balls connected by unidirectional hamster tubes of varying lengths. Harry is currently in ball \(s\) and his bed is in ball \(t\).

Being a simple hamster, Harry's brain halves are not so great at communicating with each other and have a mind of their own. Harry's left brain half, usually being active when Harry is in the hamster wheel, likes running for as long as possible. Harry's right brain half, rarely active at all, would like to go to sleep as soon as possible. Together, Harry's brain halves will be navigating Harry through the maze of tubes, in each ball deciding which of the outgoing tubes to follow.

Harry's brain halves get really tired after making a decision and then need to rest a bit, so they cannot make two decisions in a row. Thus, they make decisions on which tube to take in alternating turns, with the left brain half going first. So starting in ball \(s\), Harry's left brain half will decide on a tube to follow, ending in some ball \(u\), where Harry's left brain half will rest and Harry's right brain half will pick an outgoing tube, et cetera.

Counterintuitively, the brain halves are familiar with the entire hamster cage and can plan arbitrarily far ahead. Assuming both brain halves make optimal decisions, how long will it take for Harry to reach his bed? It is guaranteed that each ball has at least one outgoing tube, except the ball containing Harry's bed which has none (there Harry will rest easily). There are no tubes connecting a ball to itself, but there may be multiple tubes going from one ball to another.

제약
입력 형식
  • On the first line are four space-separated integers: the number of plastic balls \(1 \leq n \leq 10^5\), the number of tubes \(0 \leq m \leq 2 \cdot 10^5\), and the locations of Harry and his bed \(0 \leq s, t < n\).
  • Then \(m\) lines follow, each containing three space-separated integers describing a single tube: the ball in which the tube starts \(0 \leq a_i < n\), in which it ends \(0 \leq b_i < n\) and the time it takes to traverse \(1 \leq w_i \leq 10^4\). Note that each tube can only be traversed in one direction.
출력 형식

Print the time it takes for Harry to reach his bed, or the string infinity if Harry is doomed to roam the tubes forever.

예제 1
입력
4 5 0 3
0 1 1
1 2 2
2 0 4
2 3 1
2 3 3
출력
11
예제 2
입력
5 5 0 4
0 1 1
1 2 1
2 3 1
3 0 1
2 4 1
출력
infinity
예제 3
입력
2 1 0 1
0 1 2
출력
2
예제 4
입력
3 3 1 2
0 1 1
1 0 1
1 2 1
출력
infinity
예제 5
입력
3 2 0 1
0 2 3
2 0 3
출력
infinity
문제 정보

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

출처 ICPC BAPC 2018

평가 및 의견

H. Harry the Hamster

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

Log in to rate problems.

개별 의견

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

풀이 제출

H. Harry the Hamster

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