Skip to content

Commit

Permalink
Merge pull request #240 from AlgoLeadMe/27-H0ngJu
Browse files Browse the repository at this point in the history
27-H0ngJu
  • Loading branch information
H0ngJu authored Sep 20, 2024
2 parents 26b43ef + 2616056 commit 825c2d2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
28 changes: 28 additions & 0 deletions H0ngJu/DFS/ํŠธ๋ฆฌ์˜ ์ง€๋ฆ„.py
Original file line number Diff line number Diff line change
@@ -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))
1 change: 1 addition & 0 deletions H0ngJu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@
| 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 |
| 26์ฐจ์‹œ | 2024.08.24 | ๊ทธ๋ฆฌ๋”” | [์‹ ์ž…์‚ฌ์›](https://www.acmicpc.net/problem/1946) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/237 |
| 27์ฐจ์‹œ | 2024.08.27 | DFS | [ํŠธ๋ฆฌ์˜ ์ง€๋ฆ„](https://www.acmicpc.net/problem/1967) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/240 |

---

0 comments on commit 825c2d2

Please sign in to comment.