ํฐ์คํ ๋ฆฌ ๋ทฐ
728x90
๐ฉ ํธ๋ฆฌ(tree)
์ฝ๋
T = int(input())
def size(root):
global cnt
if tree[root][0]:
cnt += 1
size(tree[root][0])
if tree[root][1]:
cnt += 1
size(tree[root][1])
for tc in range(1, T+1):
E, N = map(int, input().split()) # ๊ฐ์ ๊ฐ์, root
tmp = list(map(int, input().split())) # ๋ถ๋ชจ-์์
tree = [[0] * 3 for _ in range(E+2)]
for i in range(E):
# [์ผ์ชฝ์์, ์ค๋ฅธ์ชฝ์์, ๋ถ๋ชจ๋
ธ๋]
parent, child = tmp[i * 2], tmp[i * 2 + 1]
tree[child][2] = parent
if not tree[parent][0]:
tree[parent][0] = child
else:
tree[parent][1] = child
cnt = 1
size(N)
print("#{} {}".format(tc, cnt))
'algorithm > swea' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[swea] 5177. ์ด์งํ / python ํ์ด์ฌ (0) | 2021.04.09 |
---|---|
[swea] 5176. ์ด์งํ์ / python ํ์ด์ฌ (0) | 2021.04.09 |
[swea] 1859. ๋ฐฑ๋ง ์ฅ์ ํ๋ก์ ํธ / python ํ์ด์ฌ (0) | 2021.04.09 |
[swea] 1961. ์ซ์ ๋ฐฐ์ด ํ์ / python ํ์ด์ฌ (0) | 2021.04.09 |
[swea] 4047. ์์ค์ด์ ์นด๋ ์นด์ดํ / python ํ์ด์ฌ (0) | 2021.04.09 |
๋๊ธ
๊ธ ๋ณด๊ดํจ
TAG
- 20056 ๋ง๋ฒ์ฌ ์์ด์ ํ์ด์ด๋ณผ
- ๋ณด์์ผํ
- ์ผ์ฑ์ฝํ
- swea
- Python
- ์๊ณ ๋ฆฌ์ฆ
- ๊ธฐ์ง๊ตญ์ค์น
- ์ผ์ฑ๊ธฐ์ถ
- git ๋ฏธ๋ฌ๋ง
- 2579 ๊ณ๋จ์ค๋ฅด๊ธฐ
- ์์ด๋๋ง์๊ธฐ
- ํ๋ก๊ทธ๋๋จธ์ค
- dfs
- 2018 ์นด์นด์ค ๊ณต์ฑ
- 21609 ์์ด ์คํ๊ต
- react
- merge ์๋ฌ
- ๋ธ๋ฃจํธํฌ์ค
- 20057 ๋ง๋ฒ์ฌ ์์ด์ ํ ๋ค์ด๋
- ํ์ด์ฌ
- ๋ฐฑ์ค
- BFS
- 17406 ๋ฐฐ์ด๋๋ฆฌ๊ธฐ4
- merge์๋ฌ
- dp
์ต๊ทผ์ ์ฌ๋ผ์จ ๊ธ
- Total
- Today
- Yesterday
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ