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

34586번 - One-Way Abyss 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 2048 MB44272660.465%

문제

Mitty is a brave adventurer exploring a mysterious underground cave system known as The Abyss. The Abyss is composed of $n$ parallel vertical shafts and $m$ horizontal tunnels. Each tunnel connects exactly two shafts at the same depth. All $m$ tunnels have distinct depths, and surprisingly, there is a treasure in the middle of every tunnel!

Mitty can pick any shaft to start with. He moves downward from the top of the chosen shaft, obeying the following rules:

  • He can only move downward, going upward is not allowed.
  • Whenever he encounters a horizontal tunnel, he must enter it immediately and will arrive at the connected shaft.
  • Once he enters a horizontal tunnel, he cannot go back.

These treasures in the tunnels have various values. Mitty wants to collect as much treasure as possible. Please help him calculate the maximum total value of treasures he can collect when starting from one of the shafts.

입력

Each test contains multiple test cases. The first line contains the number of test cases $t$. The description of the test cases follows.

The first line contains two integers $n$ and $m,ドル representing the number of vertical shafts and horizontal tunnels, respectively.

Each of the following $m$ lines contains three integers $x,ドル $y$ and $v,ドル representing a horizontal tunnel at a certain depth that connects shafts numbered $x$ and $y,ドル and contains a treasure worth $v$.

The horizontal tunnels are given from top to bottom. This implies that no two horizontal tunnels situated at the same depth.

출력

For each test case, print a single integer, representing the maximum total value of treasures Mitty can collect.

제한

  • 1ドル ≤ t ≤ 20$
  • 1ドル ≤ n ≤ 2 \times 10^5$
  • 0ドル ≤ m ≤ 2 \times 10^5$
  • 1ドル ≤ x < y ≤ n$
  • 0ドル ≤ v ≤ 10^9$
  • It is guaranteed that the sum of $n$ over all test cases does not exceed 2ドル \times 10^5$.
  • It is guaranteed that the sum of $m$ over all test cases does not exceed 2ドル \times 10^5$.

예제 입력 1

1
3 3
1 2 3
2 3 4
1 3 9

예제 출력 1

16

예제 입력 2

2
5 8
1 4 5
1 3 4
1 3 2
1 3 9
2 4 1
1 3 2
2 3 0
1 5 6
7 2
5 6 16
5 7 4

예제 출력 2

28
20

노트

출처

ICPC > Regionals > Asia Pacific > Taiwan > Taiwan Online Programming Contest > TOPC 2025 C번

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

출처

대학교 대회

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

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