728x90
๋ฌธ์
ํ์ด
๋ฑ์๋ฅผ ์ฐพ์ ๋ ธ๋ ์๋ก ๋ช ๊ฐ์ ๋ ธ๋๊ฐ ์๋์ง,
์๋๋ก ๋ช ๊ฐ์ ๋ ธ๋๊ฐ ์๋์ง ๊ตฌํ๋ฉด ๋๋ค.
์ฝ๋
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
n, m, x = map(int, input().split())
up = [[] for _ in range(n + 1)]
down = [[] for _ in range(n + 1)]
for _ in range(m):
a, b = map(int, input().split())
down[a].append(b) # a ์๋์ b
up[b].append(a) # b ์์ a
visited = [False] * (n + 1)
def dfs(x, graph, cnt):
visited[x] = True
cnt[0] += 1
for next in graph[x]:
if not visited[next]:
dfs(next, graph, cnt)
upNode = [-1]
downNode = [-1]
dfs(x, up, upNode)
dfs(x, down, downNode)
print(1 + upNode[0], end = " ")
print(n - downNode[0])
๋ง๋ฌด๋ฆฌ
๋ฐฉ๋ฒ์ ๋ ์ฌ๋ฆฌ๋๋ฐ ์๊ฐ์ด ๊ฝค ๊ฑธ๋ ธ๊ณ , ์ฝ๋ ์์ฑ์ ์ฌ์ ๋ค.
728x90