Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions 도넛과 λ§‰λŒ€ κ·Έλž˜ν”„.py
Original file line number Diff line number Diff line change
@@ -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