From dd3c8cf2d5ca408a681e363fb5c8134786224e92 Mon Sep 17 00:00:00 2001 From: ing-eoking Date: Thu, 27 Mar 2025 18:43:52 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9C=20Study:=20=EB=8F=84=EB=84=9B?= =?UTF-8?q?=EA=B3=BC=20=EB=A7=89=EB=8C=80=20=EA=B7=B8=EB=9E=98=ED=94=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0 \352\267\270\353\236\230\355\224\204.py" | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 "\353\217\204\353\204\233\352\263\274 \353\247\211\353\214\200 \352\267\270\353\236\230\355\224\204.py" diff --git "a/\353\217\204\353\204\233\352\263\274 \353\247\211\353\214\200 \352\267\270\353\236\230\355\224\204.py" "b/\353\217\204\353\204\233\352\263\274 \353\247\211\353\214\200 \352\267\270\353\236\230\355\224\204.py" new file mode 100644 index 0000000..23b9aee --- /dev/null +++ "b/\353\217\204\353\204\233\352\263\274 \353\247\211\353\214\200 \352\267\270\353\236\230\355\224\204.py" @@ -0,0 +1,20 @@ +from collections import defaultdict, deque + +def solution(edges): + answer = [0] * 4 + graph = defaultdict(lambda: [[], []]) + for e in edges: + graph[e[0]][1].append(e[1]) + graph[e[1]][0].append(e[0]) + answer[0] = next(g for g in graph + if not graph[g][0] and len(graph[g][1]) > 1) + for g in graph[answer[0]][1]: + sin, dou, s, q = False, False, {g}, deque([g]) + while q: + cur = q.popleft() + for i in graph[cur][1]: + if i not in s: s.add(i); q.append(i) + elif not sin: sin = True + else: dou = True + answer[sin + (not (sin ^ dou)) * 2] += 1 + return answer