There are
nteams numbered from0ton - 1in a tournament; each team is also a node in a DAG.You are given the integer
nand a 0-indexed 2D integer arrayedgesof lengthmrepresenting the DAG, whereedges[i] = [ui, vi]indicates that there is a directed edge from teamuito teamviin the graph.A directed edge from
atobin the graph means that teamais stronger than teamband teambis weaker than teama.Team
awill be the champion of the tournament if there is no teambthat is stronger than teama.Return the team that will be the champion of the tournament if there is a unique champion, otherwise, return
-1.Notes
- A cycle is a series of nodes
a1, a2, ..., an, an+1such that nodea1is the same node as nodean+1, the nodesa1, a2, ..., anare distinct, and there is a directed edge from the nodeaito nodeai+1for everyiin the range[1, n].- A DAG is a directed graph that does not have any cycle.
1 | class Solution { |