ABC 317 C - Remembering the Days
提出
code: python
from collections import defaultdict
n, m = map(int, input().split())
# 重みつきグラフ
d = defaultdict(list)
for a, b, c in abc:
def bfs()
解答
code: python
from collections import defaultdict
n, m = map(int, input().split())
d = defaultdict(list)
for a, b, c in abc:
visited = False * (n + 1) def dfs(v, s):
max_s = s
total = dfs(next, s + dist)
if total > max_s:
max_s = total
return max_s
ans = 0
for i in range(1, n + 1):
total = dfs(i, 0)
if total > ans:
ans = total
print(ans)
code: python
from collections import defaultdict
n, m = map(int, input().split())
graph = defaultdict(list)
for a, b, c in abc:
def dfs(start):
res = 0
stack = []
stack.append((start, 0, set(start))) while stack:
now, dist, visited = stack.pop()
res = max(res, dist)
for next, cost in graphnow: if next not in visited:
new_visited = visited.copy()
new_visited.add(next)
stack.append((next, dist + cost, new_visited))
return res
ans = 0
for i in range(1, n + 1):
total = dfs(i)
ans = max(ans, total)
print(ans)
テーマ