๋ฌธ์
https://www.acmicpc.net/problem/1068
ํ์ด
# ๋ฐฑ์ค 1068๋ฒ ๋ฌธ์ - ํธ๋ฆฌ
n = int(input())
node = list(map(int, input().split()))
m = int(input())
cnt = 0
def dfs(n, node):
node[n] = -2
for i in range(len(node)):
if n == node[i]:
dfs(i, node)
dfs(m, node)
for i in range(len(node)):
if node[i] != -2 and i not in node:
cnt += 1
print(cnt)
'๐๏ธ Algorithm > ๐ฉ ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๐ฉ [๋ฐฑ์ค] [Python] [Silver1] 1303๋ฒ_์ ์-์ ํฌ (0) | 2023.02.09 |
---|---|
๐ฉ [๋ฐฑ์ค] [Python] [Silver1] 2504๋ฒ_๊ดํธ์ ๊ฐ (0) | 2023.02.08 |
๐ฉ [๋ฐฑ์ค] [Python] [Gold4] 2573๋ฒ_๋น์ฐ (0) | 2023.01.04 |
๐ฉ [๋ฐฑ์ค] [Python] 13549๋ฒ_์จ๋ฐ๊ผญ์ง 3 (0) | 2022.12.17 |
๐ฉ [๋ฐฑ์ค] [Python] 24444๋ฒ_์๊ณ ๋ฆฌ์ฆ ์์ - ๋๋น ์ฐ์ ํ์ 1 (0) | 2022.12.16 |