From e6ff9a5fd4781c327f0f22f242f9d27790ea6d68 Mon Sep 17 00:00:00 2001 From: H0ngJu Date: Tue, 27 Aug 2024 23:02:47 +0900 Subject: [PATCH] 2024-08-27 --- ...4\354\235\230 \354\247\200\353\246\204.py" | 28 +++++++++++++++++++ H0ngJu/README.md | 8 ++++-- ...44\355\212\270\354\225\250\353\262\224.py" | 0 3 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 "H0ngJu/DFS/\355\212\270\353\246\254\354\235\230 \354\247\200\353\246\204.py" rename "H0ngJu/\353\262\240\354\212\244\355\212\270\354\225\250\353\262\224.py" => "H0ngJu/\355\225\264\354\213\234/\353\262\240\354\212\244\355\212\270\354\225\250\353\262\224.py" (100%) diff --git "a/H0ngJu/DFS/\355\212\270\353\246\254\354\235\230 \354\247\200\353\246\204.py" "b/H0ngJu/DFS/\355\212\270\353\246\254\354\235\230 \354\247\200\353\246\204.py" new file mode 100644 index 00000000..7fb0fd9f --- /dev/null +++ "b/H0ngJu/DFS/\355\212\270\353\246\254\354\235\230 \354\247\200\353\246\204.py" @@ -0,0 +1,28 @@ +import sys +sys.setrecursionlimit(10**9) +def input() : return sys.stdin.readline().rstrip() + +n = int(input()) +tree = [[] for _ in range(n+1)] +visited = [-1] * (n+1) +visited[1] = 0 + +for i in range(n-1): + v, u, w = map(int, input().split()) + tree[v].append((u, w)) + tree[u].append((v, w)) + +def dfs(start, dis): + for node, node_dis in tree[start]: + if visited[node] == -1: + visited[node] = dis + node_dis + dfs(node, dis + node_dis) + +dfs(1,0) + +far_node = visited.index(max(visited)) +visited = [-1] * (n+1) +visited[far_node] = 0 +dfs(far_node, 0) + +print(max(visited)) \ No newline at end of file diff --git a/H0ngJu/README.md b/H0ngJu/README.md index 0ccf56d0..e220aaaa 100644 --- a/H0ngJu/README.md +++ b/H0ngJu/README.md @@ -24,8 +24,10 @@ | 20차시 | 2024.06.03 | 백트래킹 | [스타트와 링크](https://www.acmicpc.net/problem/14889) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/206 | | 21차시 | 2024.06.07 | 그리디 | [행복 유치원](https://www.acmicpc.net/problem/13164) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/208 | | 22차시 | 2024.08.06 | 해시 | [의상](https://school.programmers.co.kr/learn/courses/30/lessons/42578) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/224 | -| 23차시 | 2024.08.10 | 해시 | [베스트앨범](https://school.programmers.co.kr/learn/courses/30/lessons/42579) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/227 | -| 24차시 | 2024.08.17 | BFS | [아기상어](https://www.acmicpc.net/problem/16236) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/233 | -| 25차시 | 2024.08.17 | DFS | [친구비](https://www.acmicpc.net/problem/16562) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/234 | +| 23차시 | 2024.08.10 | 해시 | [베스트앨범](https://school.programmers.co.kr/learn/courses/30/lessons/42579) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/227 | +| 24차시 | 2024.08.17 | BFS | [아기상어](https://www.acmicpc.net/problem/16236) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/233 | +| 25차시 | 2024.08.17 | DFS | [친구비](https://www.acmicpc.net/problem/16562) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/234 | + +| 27차시 | 2024.08.27 | DFS | [트리의 지름](https://www.acmicpc.net/problem/1967) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/240 | --- diff --git "a/H0ngJu/\353\262\240\354\212\244\355\212\270\354\225\250\353\262\224.py" "b/H0ngJu/\355\225\264\354\213\234/\353\262\240\354\212\244\355\212\270\354\225\250\353\262\224.py" similarity index 100% rename from "H0ngJu/\353\262\240\354\212\244\355\212\270\354\225\250\353\262\224.py" rename to "H0ngJu/\355\225\264\354\213\234/\353\262\240\354\212\244\355\212\270\354\225\250\353\262\224.py"