There are
n
teams numbered from0
ton - 1
in a tournament; each team is also a node in a DAG.You are given the integer
n
and a 0-indexed 2D integer arrayedges
of lengthm
representing the DAG, whereedges[i] = [ui, vi]
indicates that there is a directed edge from teamui
to teamvi
in the graph.A directed edge from
a
tob
in the graph means that teama
is stronger than teamb
and teamb
is weaker than teama
.Team
a
will be the champion of the tournament if there is no teamb
that 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+1
such that nodea1
is the same node as nodean+1
, the nodesa1, a2, ..., an
are distinct, and there is a directed edge from the nodeai
to nodeai+1
for everyi
in the range[1, n]
.- A DAG is a directed graph that does not have any cycle.
1 | class Solution { |