C - Remembering the Days Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 300300

問題文

ある地方に、11 から NN の番号がついた NN 個の街と、11 から MM の番号がついた MM 本の道路があります。

ii 番目の道路は街 AiA_i と街 BiB_i を双方向に結び、長さは CiC_i です。

好きな街からスタートして同じ街を二度以上通らずに別の街へ移動するときの、通る道路の長さの和としてありえる最大値を求めてください。

制約

  • 2N102 \leq N \leq 10
  • 1MN(N1)21 \leq M \leq \frac{N(N-1)}{2}
  • 1Ai<BiN1\leq A_i < B_i \leq N
  • (Ai,Bi)(A_i,B_i) は相異なる
  • 1Ci1081\leq C_i \leq 10^8
  • 入力は全て整数である

入力

入力は以下の形式で標準入力から与えられる。

NN MM
A1A_1 B1B_1 C1C_1
\vdots
AMA_M BMB_M CMC_M

出力

答えを出力せよ。


入力例 1Copy

Copy
4 4
1 2 1
2 3 10
1 3 100
1 4 1000

出力例 1Copy

Copy
1110

41324\to 1\to 3\to 2 と移動すると、通る道路の長さの和は 11101110 となります。


入力例 2Copy

Copy
10 1
5 9 1

出力例 2Copy

Copy
1

道路と繋がっていない街が存在するかもしれません。


入力例 3Copy

Copy
10 13
1 2 1
1 10 1
2 3 1
3 4 4
4 7 2
4 8 1
5 8 1
5 9 3
6 8 1
6 9 5
7 8 1
7 9 4
9 10 3

出力例 3Copy

Copy
20

図

Score : 300300 points

Problem Statement

A region has NN towns numbered 11 to NN, and MM roads numbered 11 to MM.

The ii-th road connects town AiA_i and town BiB_i bidirectionally with length CiC_i.

Find the maximum possible total length of the roads you traverse when starting from a town of your choice and getting to another town without passing through the same town more than once.

Constraints

  • 2N102 \leq N \leq 10
  • 1MN(N1)21 \leq M \leq \frac{N(N-1)}{2}
  • 1Ai<BiN1 \leq A_i < B_i \leq N
  • The pairs (Ai,Bi)(A_i,B_i) are distinct.
  • 1Ci1081\leq C_i \leq 10^8
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN MM
A1A_1 B1B_1 C1C_1
\vdots
AMA_M BMB_M CMC_M

Output

Print the answer.


Sample Input 1Copy

Copy
4 4
1 2 1
2 3 10
1 3 100
1 4 1000

Sample Output 1Copy

Copy
1110

If you travel as 41324\to 1\to 3\to 2, the total length of the roads you traverse is 11101110.


Sample Input 2Copy

Copy
10 1
5 9 1

Sample Output 2Copy

Copy
1

There may be a town that is not connected to a road.


Sample Input 3Copy

Copy
10 13
1 2 1
1 10 1
2 3 1
3 4 4
4 7 2
4 8 1
5 8 1
5 9 3
6 8 1
6 9 5
7 8 1
7 9 4
9 10 3

Sample Output 3Copy

Copy
20

Figure



2025-04-21 (Mon)
04:00:12 +00:00