Skip to content

Commit

Permalink
Merge pull request #37 from AlgoLeadMe/9-fnzksxl
Browse files Browse the repository at this point in the history
9-fnzksxl
  • Loading branch information
fnzksxl authored Mar 7, 2024
2 parents ad8098b + 419ba10 commit e855279
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions fnzksxl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
| 6μ°¨μ‹œ | 2024-02-14 | DP | [λ“±κ΅£κΈΈ](https://school.programmers.co.kr/learn/courses/30/lessons/42898) | [#28](https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/28) |
| 7μ°¨μ‹œ | 2024-02-18 | 그리디 | [ꡬλͺ…λ³΄νŠΈ](https://school.programmers.co.kr/learn/courses/30/lessons/42885) | [#30](https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/30) |
| 8μ°¨μ‹œ | 2024-02-20 | DP | [동전1](https://www.acmicpc.net/problem/2293) | [#32](https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/32) |
| 9μ°¨μ‹œ | 2024-02-23 | κ·Έλž˜ν”„ | [μˆœμœ„](https://school.programmers.co.kr/learn/courses/30/lessons/49191) | [#37](https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/37) |
---
39 changes: 39 additions & 0 deletions fnzksxl/κ·Έλž˜ν”„/μˆœμœ„.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from collections import deque

def func(n, graph, degree):
for i in range(1, n+1):
q = deque()
q.append(i)

while q:
node = q.popleft()

for next_node in graph[node]:
_before = len(degree[i])
degree[i].add(next_node)

if _before == len(degree[i]):
continue

q.append(next_node)

def solution(n, results):
answer = 0
graph = [[] for _ in range(n+1)]
reversed_graph = [[] for _ in range(n+1)]
in_degree = [set() for _ in range(n+1)]
out_degree = [set() for _ in range(n+1)]

for win, defeat in results:
graph[win].append(defeat)
reversed_graph[defeat].append(win)

func(n, graph, out_degree)
func(n, reversed_graph, in_degree)


for i in range(1, n+1):
if len(out_degree[i])+len(in_degree[i]) == n-1:
answer += 1

return answer

0 comments on commit e855279

Please sign in to comment.