[TIL] 210930

백규현·2021년 9월 30일
0

TIL

목록 보기
8/10
  • 백준에 있는 트리 문제들을 공부했다.
    맞은문제 : 1991 / 1068 / 5639
    해결 못한 문제 :
    1967번을 이렇게 풀었는데 왜 틀렸는지 아직 못찾았다. 반례라도 알려주면 고칠것 같은데...
import sys
from collections import defaultdict
I = sys.stdin.readline
weights=defaultdict(int)
weights2=defaultdict(int)
n = int(I())
if n==1 : print(0);exit(0)
for line in reversed([I() for _ in range(n-1)]):
    parent,son,weight=map(int,line.split())
    weights2[parent]+=(weight+weights[son])
    weights[parent] = max(weights[parent],weight+weights[son])
print(max(weights2.items(),key= lambda x : x[1])[1])

2263번 : 트리 순회문제가 아직 익숙하지 않은 것 같다.
11437번 : LCA,SegmentTree 를 새로 공부해야된다.

골드이상되면 새로운 알고리즘을 공부해야 풀리는 문제들이 많아서 생각보다 시간이 오래 걸리고 있다...

profile
반갑습니다.

0개의 댓글