Skip to content

Commit 39b296d

Browse files
committed
108차 3번 문제풀이
1 parent 59ee5a7 commit 39b296d

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import sys
2+
from collections import defaultdict
3+
4+
sys.setrecursionlimit(10**6)
5+
count = 0
6+
7+
def main():
8+
input = sys.stdin.readline
9+
N, W = map(int, input().split())
10+
11+
tree = defaultdict(list)
12+
13+
for _ in range(N-1):
14+
u, v = map(int, input().split())
15+
tree[u].append(v)
16+
tree[v].append(u)
17+
18+
def dfs(node, parent):
19+
global count
20+
isLeaf = True
21+
for child in tree[node]:
22+
if child != parent:
23+
isLeaf = False
24+
dfs(child, node)
25+
if isLeaf:
26+
count += 1
27+
28+
dfs(1, -1)
29+
30+
print(W / count)
31+
32+
if __name__ == '__main__':
33+
main()

0 commit comments

Comments
 (0)