結果

問題 No.845 最長の切符
ユーザー rusa6111
提出日時 2019-06-28 21:48:01
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 464 bytes
コンパイル時間 165 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 86,016 KB
最終ジャッジ日時 2024-07-02 04:36:05
合計ジャッジ時間 5,567 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 7 TLE * 1 -- * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m=tuple(map(int,input().split()))
way=[set() for i in range(n)]
for i in range(m):
	inp=tuple(map(int,input().split()))
	way[inp[0]-1].add((inp[1]-1,inp[2]))
	way[inp[1]-1].add((inp[0]-1,inp[2]))
def longest(fr,to,without):
	maxd=0
	for i in way[fr]:
		if not (i[0] in without):
			d=i[1]+longest(i[0],to,without+[fr])
			if d>maxd:
				maxd=d
	return maxd
maxd=0
for i in range(n):
	for j in range(i+1,m):
		d=longest(i,j,[])
		if maxd<d:
			maxd=d
print(maxd)
0