DAG ko có circle, đây là nhiều hơn 1 champions nên trả về -1 thôi. Bác đọc kỹ đề đi.Xem tệp đính kèm 2801269
Đề bài bảo ko circle, troll quá
Python:class Solution: def findChampion(self, n: int, edges: List[List[int]]) -> int: graph = defaultdict(list) for u, v in edges: graph[u].append(v) def bfs(node): cnt = 0 q = deque([node]) visited = {node} while q: curr = q.popleft() cnt += 1 for nei in graph[curr]: if nei not in visited: q.append(nei) visited.add(nei) return cnt == n champs = [i for i in range(n) if bfs(i)] return champs[0] if len(champs) == 1 else -1

), để thử làm mono stack

