-
[백준 문제풀이] 얼렁뚱땅 1967번 트리의 지름 풀이얼렁뚱땅 백준 문제풀이 2022. 7. 15. 14:04
https://www.acmicpc.net/problem/1967 감자에겐 너무 어렵군요 ^^..
import sys sys.setrecursionlimit(10**9) n = int(input()) array = [[] for i in range(n+1)] for _ in range(n-1) : start, end, path = map(int,input().split()) array[start].append([end,path]) array[end].append([start,path]) distance = [-1] * (n+1) distance[1] = 0 def dfs(x,wei) : for i in array[x] : a,b = i if distance[a] == -1 : distance[a] = wei + b dfs(a, wei+b) dfs(1,0) new_start = distance.index(max(distance)) distance = [-1] * (n+1) distance[new_start] = 0 dfs(new_start,0) print(max(distance))
'얼렁뚱땅 백준 문제풀이' 카테고리의 다른 글
[백준 문제풀이] 얼렁뚱땅 15656 N과 M 풀이 (0) 2022.07.25 [백준 문제풀이] 얼렁뚱땅 10974 모든 순열 풀이 (0) 2022.07.25 [백준 문제풀이] 23291번 파일 정리 풀이 (0) 2022.07.05 [백준 문제풀이] 얼렁뚱땅 1166번 선물 풀이 (0) 2022.07.05 [백준 문제풀이] 얼렁뚱땅 18405번 경쟁적 전염 풀이 (0) 2022.07.01