Find Champion II

Medium

A tournament has n teams, labeled from 0 to n - 1. Its results form a directed acyclic graph: each team is a node, and there are no cycles.

You are given an array edges, where edges[i] = [u_i, v_i] means team u_i is stronger than team v_i.

Strength carries through chains: if team a is stronger than team b, and team b is stronger than team c, then team a is stronger than team c.

A team is the champion if no other team is stronger than it. Return the champion if there is exactly one. Otherwise, return -1.

Examples

Example 1

Input:  n = 3, edges = [[0,1],[1,2]]
Output: 0

Team 0 is stronger than team 1, and team 1 is stronger than team 2. Nobody is stronger than team 0.

Example 2

Input:  n = 4, edges = [[0,2],[1,3],[1,2]]
Output: -1

Nobody is stronger than team 0, and nobody is stronger than team 1. Two teams qualify, so there's no single champion.

Example 3

Input:  n = 3, edges = [[0,1]]
Output: -1

Team 2 isn't in any edge, but nobody is stronger than it. So teams 0 and 2 both qualify. A team with no edges still counts.

Example 1012One unbeaten teamAnswer: 0Example 20123Two unbeaten teamsAnswer: -1Example 3012Team 2 has no games,but it's unbeaten: -1

Example 4

Input:  n = 1, edges = []
Output: 0

The only team has nobody stronger than it, so it's the champion.

Example 5

Input:  n = 4, edges = [[1,0],[1,2],[0,3],[2,3]]
Output: 1

Teams 0 and 2 are both stronger than team 3, and team 1 is stronger than both of them. Only team 1 has nobody above it.

Constraints

  • 1 <= n <= 100
  • 0 <= edges.length <= n * (n - 1) / 2
  • edges[i].length == 2
  • 0 <= u_i, v_i <= n - 1
  • u_i != v_i
  • The graph has no cycles and no repeated edges.
TypeScript
Loading editor…
Test cases38
Case 1
n = 3
edges = [[0,1],[1,2]]
Case 2
n = 4
edges = [[0,2],[1,3],[1,2]]
Case 3
n = 3
edges = [[0,1]]
Case 4
n = 1
edges = []
Case 5
n = 4
edges = [[1,0],[1,2],[0,3],[2,3]]
Case 6
n = 2
edges = []
Case 7
n = 2
edges = [[0,1]]
Case 8
n = 2
edges = [[1,0]]
Case 9
n = 3
edges = []
Case 10
n = 3
edges = [[2,1],[2,0]]
Case 11
n = 3
edges = [[2,0],[0,1]]
Case 12
n = 3
edges = [[1,0],[1,2]]
Case 13
n = 4
edges = [[3,2],[2,1],[1,0]]
Case 14
n = 4
edges = [[3,0],[3,1],[2,0]]
Case 15
n = 5
edges = [[1,0],[2,0],[3,0],[4,0]]
Case 16
n = 5
edges = [[0,1],[0,2],[0,3],[0,4]]
Case 17
n = 5
edges = [[0,1],[0,2],[0,3]]
Case 18
n = 4
edges = [[0,1],[2,3]]
Case 19
n = 5
edges = [[4,3],[3,2],[2,1]]
Case 20
n = 6
edges = [[5,4],[5,3],[4,2],[3,2],[2,1],[2,0]]
Case 21
n = 6
edges = [[5,4],[5,3],[4,2],[3,2],[1,2],[2,0]]
Case 22
n = 5
edges = [[0,1],[0,3],[2,0],[1,4],[3,1],[0,4]]
Case 23
n = 5
edges = [[0,1],[0,2],[4,3],[2,1],[4,1],[2,3]]
Case 24
n = 7
edges = [[5,2],[1,0],[4,3],[4,6],[1,5],[2,3],[2,0],[5,4],[5,3]]
Case 25
n = 7
edges = [[2,6],[4,3],[5,2],[5,0],[4,0],[0,1],[0,6],[4,6],[1,6]]
Case 26
n = 10
edges = [[3,5],[8,9],[8,1],[6,8],[3,4],[3,7],[3,2],[1,4],[2,8],[5,0],[5,9],[3,6],[3,0],[6,0]]
Case 27
n = 10
edges = [[7,1],[6,2],[7,8],[3,6],[1,6],[3,4],[8,1],[9,6],[1,4],[5,2],[9,2],[7,0],[7,9],[5,3]]
Case 28
n = 20
edges = [[5,12],[5,11],[15,1],[16,9],[0,11],[6,5],[19,0],[19,14],[6,11],[2,10],[1,12],[8,14],[15,2],[0,7],[1,13],[19,12],[12,8],[2,19],[19,16],[15,11],[15,17],[7,10],[11,8],[7,9],[15,6],[1,18],[13,12],[1,3],[3,8],[1,4]]
Case 29
n = 20
edges = [[8,18],[9,4],[14,0],[9,13],[4,8],[0,10],[15,16],[9,3],[3,1],[0,3],[9,10],[9,15],[12,13],[17,13],[14,8],[6,5],[17,12],[15,4],[4,11],[12,7],[16,2],[15,17],[14,6],[2,7],[9,17],[6,13],[17,6],[15,5],[9,11],[4,19]]
Case 30
n = 35
edges = [[21,5],[23,21],[16,2],[16,18],[16,7],[1,7],[27,31],[16,17],[5,17],[1,20],[10,4],[23,15],[20,19],[8,22],[24,30],[5,28],[0,19],[26,34],[18,32],[4,13],[23,19],[18,27],[16,30],[22,33],[29,2],[21,0],[26,33],[4,28],[1,5],[29,20],[8,5],[29,13],[29,0],[24,7],[16,1],[20,24],[23,0],[31,33],[1,29],[29,10],[3,34],[1,11],[4,22],[27,12],[24,9],[11,9],[10,25],[32,17],[16,23],[18,24],[27,25],[14,21],[24,15],[14,8],[20,14],[34,9],[29,3],[23,26],[18,23],[0,6]]
Case 31
n = 35
edges = [[19,27],[32,18],[8,20],[13,12],[27,18],[7,18],[4,1],[14,1],[8,0],[17,25],[22,23],[24,34],[27,7],[19,15],[18,26],[8,33],[17,5],[17,13],[3,32],[17,29],[20,26],[10,22],[14,24],[19,3],[10,34],[22,27],[27,21],[14,8],[22,24],[3,18],[31,28],[0,12],[33,31],[10,9],[5,29],[16,8],[27,14],[16,13],[17,4],[15,25],[16,19],[5,28],[7,26],[19,18],[15,30],[16,6],[21,26],[4,31],[8,7],[29,21],[0,6],[17,16],[9,11],[33,23],[23,18],[15,2],[0,21],[7,30],[1,0],[1,6]]
Case 32
n = 9
edges = [[6,1],[4,3],[0,2],[4,7],[0,4],[7,2],[4,5],[5,6]]
Case 33
n = 25
edges = [[17,16],[24,17],[17,22],[20,14],[24,22],[9,19],[10,16],[10,4],[11,18],[12,10],[21,2],[20,23],[24,5],[21,20],[22,0],[22,15],[9,12],[21,3],[14,18],[23,16],[14,0],[9,16],[9,14],[22,7],[5,1],[2,11],[3,7],[11,9],[3,24],[24,8]]
Case 34
n = 100
edges = [[84,23],[36,45],[36,65],[91,78],[29,13],[97,13],[98,50],[70,58],[87,63],[65,61],[57,15],[88,26],[19,18],[2,80],[97,56],[75,16],[98,6],[47,44],[47,5],[68,60],[92,35],[77,35],[99,4],[9,44],[15,7],[11,81],[99,70],[99,97],[86,17],[16,0],[75,71],[24,75],[37,55],[28,4],[92,25],[72,81],[57,83],[55,58],[86,4],[99,21],[18,62],[36,21],[14,18],[25,23],[47,4],[16,6],[31,45],[77,40],[29,67],[74,81],[90,20],[46,50],[78,84],[61,71],[87,20],[98,53],[69,3],[42,71],[95,0],[37,8],[27,68],[24,20],[19,63],[49,7],[97,90],[59,6],[94,85],[49,38],[16,11],[75,57],[47,80],[43,11],[77,14],[9,34],[28,45],[46,5],[9,33],[46,22],[98,20],[78,43],[88,7],[74,79],[10,22],[85,67],[91,71],[29,47],[96,0],[49,81],[65,3],[92,34],[79,45],[11,83],[49,33],[49,61],[8,75],[8,14],[91,57],[87,32],[9,67],[27,48],[39,53],[92,17],[92,51],[19,73],[11,18],[84,45],[32,67],[64,86],[46,91],[72,3],[82,85],[33,50],[62,23],[25,4],[42,14],[99,42],[41,65],[54,52],[2,85],[97,43],[78,88],[2,32],[30,0],[91,54],[22,32],[70,59],[40,83],[63,17],[24,16],[75,50],[94,7],[77,79],[78,6],[31,32],[36,67],[14,95],[87,88],[48,3],[69,79],[53,6],[24,91],[68,73],[94,15],[9,79],[69,50],[9,32],[97,84],[95,47],[46,60],[83,17],[36,33],[36,38],[7,26],[57,49],[23,38],[79,96],[64,82],[74,1],[12,58],[15,48],[36,71],[99,9],[50,28],[19,81],[55,34],[47,54],[46,69],[20,51],[55,89],[8,60],[33,48],[39,14],[98,86],[69,40],[37,87],[57,2],[3,4],[85,58],[14,80],[31,71],[37,29],[27,82],[16,28],[89,4],[95,51],[15,41],[96,38],[92,10],[53,25],[37,22],[42,78],[9,68],[66,32],[69,22],[36,82],[66,98],[92,84],[11,7],[97,38],[60,21],[97,19],[53,48],[19,89],[69,34],[46,82],[99,24],[64,83],[29,58],[99,34],[34,98],[37,97],[57,85],[66,65],[84,30],[18,48],[66,40],[86,33],[76,13],[41,53],[24,64],[44,45],[88,20],[6,12],[55,33],[75,72],[76,94],[43,64],[44,17],[56,81],[20,45],[42,6],[24,23],[56,22],[87,67],[9,89],[94,11],[27,77],[68,33],[99,30],[37,6],[22,45],[83,28],[51,44],[83,71],[84,36],[53,7],[78,34],[42,96],[6,0],[90,41],[31,73],[78,5],[8,2],[95,80],[57,20],[69,70],[19,13],[37,62],[95,23],[91,83],[69,51],[91,49],[64,32],[72,4],[27,23],[13,61],[74,49],[20,67],[72,38],[10,58],[98,48],[99,67],[31,88],[97,16],[74,84],[37,76],[41,89],[70,31],[74,16],[75,11],[50,5],[64,21],[88,61],[80,20],[41,32],[2,68],[2,18],[20,82],[32,28],[6,58],[1,32],[8,74],[49,88],[51,26],[95,20],[76,16],[33,21],[31,96],[84,19],[29,73],[19,5],[57,87],[42,64],[29,38],[1,94],[27,41],[84,98],[73,3],[18,13],[91,90],[57,28],[8,13],[16,52],[41,72],[11,4],[99,53],[39,23],[15,62],[91,17],[5,12],[15,96],[10,83],[78,79],[14,19],[77,90],[50,21],[92,88],[1,87],[66,95],[27,31],[46,49],[1,78],[70,54],[39,96],[59,3],[68,62],[92,79],[79,44],[63,12],[28,71],[91,10],[56,82],[91,73],[49,44],[18,82],[84,54],[93,45],[16,10],[91,81],[25,83],[53,32],[80,54],[52,58],[97,5],[15,65],[29,34],[74,99],[16,21],[57,89],[6,33],[85,96],[59,90],[87,13],[2,10],[36,6],[37,79],[57,47],[92,70],[1,44],[88,45],[1,67],[78,93],[16,20],[94,81],[74,86],[77,9],[79,63],[19,17],[56,69],[47,18],[26,17],[92,47],[47,83],[9,42],[79,36],[66,39],[8,85],[42,4],[74,25],[88,30],[77,11],[18,12],[91,92],[91,20],[12,52],[95,63],[37,64],[98,51],[46,8],[46,27],[93,60],[12,0],[25,44],[36,60],[78,98],[69,32],[94,86],[72,48],[64,60],[47,62],[43,41],[78,87],[16,85],[37,16],[64,25],[88,72],[34,61],[99,78],[31,47],[43,55],[84,63],[53,82],[31,87],[94,2],[29,88],[32,80],[29,45],[95,3],[95,64],[43,23],[59,93],[76,30],[35,96],[34,23],[46,37],[56,31],[55,19],[93,35],[24,56],[66,25],[72,60],[27,66],[34,47],[59,60],[70,3],[27,19],[47,32],[37,72],[1,83],[43,82],[10,23],[19,22],[9,66],[66,79],[94,84],[77,10],[43,40],[99,68],[99,11],[10,86],[63,25],[69,85],[79,13],[47,67],[86,88],[77,26],[33,82],[32,85],[5,48],[5,85],[8,34],[64,7],[43,94],[59,34],[24,72],[8,33],[76,39],[37,59],[75,92],[64,71],[57,92],[31,51],[59,30],[88,54],[86,32],[9,40],[7,96],[76,84],[83,52],[35,21],[83,7],[39,47],[78,95],[36,49],[35,38],[75,40],[32,12],[57,14],[35,51],[87,80]]
Case 35
n = 100
edges = [[53,94],[20,48],[52,84],[20,89],[60,41],[84,29],[16,34],[46,4],[68,11],[83,28],[26,99],[42,1],[67,72],[90,74],[22,60],[65,48],[82,27],[50,42],[44,58],[61,98],[61,27],[44,81],[25,98],[9,2],[53,2],[97,95],[12,44],[25,9],[99,95],[50,61],[17,73],[76,97],[72,20],[26,2],[56,94],[78,10],[79,85],[45,35],[95,46],[83,80],[53,73],[69,41],[76,43],[65,58],[90,79],[76,51],[99,75],[55,22],[31,58],[96,99],[31,88],[47,35],[30,70],[60,28],[16,45],[45,60],[77,54],[48,2],[78,80],[90,69],[78,88],[47,99],[82,80],[40,79],[0,94],[40,33],[96,21],[38,80],[86,28],[93,48],[96,85],[31,45],[57,32],[69,53],[73,2],[14,66],[82,7],[59,82],[78,30],[18,56],[66,73],[62,43],[78,14],[99,33],[63,41],[55,21],[31,96],[25,4],[7,38],[99,13],[68,2],[75,89],[41,73],[65,99],[12,13],[66,4],[21,22],[20,2],[14,60],[47,62],[76,37],[40,6],[72,15],[77,10],[65,53],[82,79],[60,0],[90,55],[76,31],[65,56],[79,94],[44,8],[61,70],[52,48],[11,8],[61,80],[82,61],[6,88],[65,24],[96,94],[31,26],[18,98],[24,86],[45,86],[59,67],[62,86],[82,41],[90,35],[96,36],[49,62],[13,56],[84,17],[90,3],[13,81],[62,11],[42,73],[40,38],[85,81],[44,42],[64,70],[75,24],[65,83],[59,77],[60,38],[63,15],[55,99],[47,75],[67,35],[79,1],[64,65],[67,60],[14,46],[31,85],[25,13],[44,86],[69,60],[87,5],[31,71],[50,78],[68,1],[78,57],[40,89],[13,1],[53,32],[21,11],[69,1],[37,85],[18,87],[19,42],[47,25],[67,83],[47,7],[53,87],[69,11],[37,51],[97,86],[6,12],[53,86],[59,76],[55,52],[3,88],[31,81],[90,14],[1,2],[29,43],[76,86],[42,38],[59,32],[97,83],[97,85],[50,39],[91,63],[34,71],[27,60],[47,29],[24,20],[9,1],[65,11],[86,10],[14,44],[59,40],[31,64],[7,42],[50,70],[24,46],[84,51],[75,29],[77,92],[42,4],[31,94],[83,42],[78,63],[77,50],[70,86],[26,41],[76,91],[15,89],[45,73],[49,8],[64,18],[7,39],[85,80],[93,23],[82,68],[12,7],[40,95],[6,60],[56,80],[69,72],[53,56],[12,61],[93,19],[74,43],[99,37],[93,32],[53,24],[26,62],[54,36],[83,0],[84,63],[18,94],[67,49],[45,30],[25,0],[12,58],[93,4],[92,4],[99,84],[65,84],[24,74],[31,49],[76,25],[40,44],[91,95],[30,11],[76,71],[59,27],[45,33],[96,4],[60,39],[30,51],[50,93],[89,4],[27,51],[65,47],[50,63],[12,34],[21,47],[67,20],[64,16],[37,30],[67,22],[56,8],[55,67],[72,9],[54,98],[97,17],[64,13],[79,38],[90,58],[38,89],[6,24],[44,56],[22,17],[49,5],[55,84],[64,10],[67,16],[45,79],[59,6],[79,3],[47,17],[74,28],[44,0],[74,89],[85,38],[23,48],[50,22],[25,58],[34,44]]
Case 36
n = 100
edges = [[2,8],[79,33],[67,5],[46,48],[17,91],[20,3],[86,7],[39,83],[47,7],[55,26],[71,95],[3,56],[21,65],[55,96],[60,97],[74,15],[23,93],[52,98],[85,71],[12,72],[40,23],[64,5],[11,45],[60,10],[55,79],[93,82],[61,11],[80,40],[93,36],[26,45],[38,37],[91,45],[46,82],[18,82],[3,14],[41,6],[47,94],[90,44],[26,99],[23,59],[88,76],[34,4],[67,58],[35,25],[10,17],[15,71],[32,36],[2,9],[84,96],[85,46],[1,50],[54,43],[7,16],[20,12],[35,29],[14,48],[26,37],[91,30],[46,52],[58,82],[91,52],[28,64],[94,43],[12,4],[20,63],[34,75],[84,60],[54,61],[65,97],[7,77],[37,45],[80,66],[38,99],[17,81],[55,31],[38,89],[21,7],[85,81],[2,87],[34,95],[68,56],[2,84],[55,39],[68,97],[57,51],[2,86],[70,98],[4,99],[67,75],[86,9],[20,67],[38,30],[19,2],[2,85],[94,69],[82,26],[33,42],[39,44],[19,47],[28,46],[40,74],[20,9],[55,48],[18,58],[20,1],[55,68],[28,79],[81,32],[75,83],[58,50],[61,69],[20,82],[77,91],[70,97],[87,38],[55,51],[55,90],[35,22],[21,64],[44,56],[77,63],[28,11],[64,57],[7,55],[44,42],[66,73],[65,89],[39,31],[8,16],[12,89],[42,50],[57,30],[13,37],[86,61],[33,49],[2,37],[19,69],[86,17],[59,8],[77,69],[39,54],[19,5],[10,24],[80,19],[87,37],[12,70],[41,63],[10,32],[75,60],[21,97],[75,39],[34,0],[55,88],[75,10],[80,60],[20,5],[74,60],[23,50],[14,76],[19,9],[84,35],[3,75],[79,65],[51,72],[47,78],[87,24],[3,41],[67,64],[71,27],[22,76],[62,18],[19,66],[20,62],[54,49],[11,29],[67,13],[71,43],[93,91],[77,10],[52,16],[75,6],[12,56],[44,6],[34,66],[90,69],[74,24],[2,20],[28,58],[24,36],[86,92],[62,34],[65,13],[23,28],[55,46],[20,21],[3,33],[35,88],[2,31],[17,25],[31,96]]
Case 37
n = 45
edges = [[18,35],[7,24],[28,38],[25,14],[34,13],[31,3],[7,14],[0,37],[29,33],[16,23],[5,10],[27,34],[0,10],[17,25],[43,13],[30,32],[11,35],[22,2],[20,33],[12,29],[24,13],[10,13],[43,34],[21,10],[15,31],[26,18],[26,34],[44,9],[8,2],[44,37],[15,39],[3,9],[18,38],[35,43],[21,19],[14,13],[1,29],[8,5],[26,13],[8,10],[10,38],[26,35],[40,12],[8,26],[17,12],[15,36],[24,32],[0,27],[40,36],[15,28],[3,12],[4,21],[41,27],[27,10],[4,31],[0,5],[5,28],[9,13],[17,1],[40,23],[17,33],[5,42],[4,20],[8,24],[39,33],[36,43],[24,23],[17,5],[11,9],[22,30],[6,28],[30,29],[24,33],[31,18],[41,40],[7,38],[30,43],[31,12],[6,18],[36,28],[1,24],[4,3],[25,32],[17,0],[15,6],[17,24],[44,40],[31,25],[8,31],[44,29],[41,1],[18,28],[15,0],[12,19],[15,5],[15,7],[6,1],[17,9],[17,40],[8,25],[5,13],[25,29],[15,3],[5,11],[37,11],[32,23],[22,38],[35,13],[20,27],[21,23],[22,12],[31,36],[36,13],[29,23],[42,32],[0,35],[31,28],[16,43],[14,28],[17,29],[7,13],[1,9],[31,19],[15,10],[44,38],[1,3],[28,43],[29,10],[6,11],[26,38],[16,34],[17,2],[22,16],[30,34],[44,39],[5,27],[44,18],[38,19],[20,11],[42,2],[27,2],[26,29],[20,30],[6,5],[5,36],[11,34],[21,12],[11,19],[41,5],[18,16],[37,19],[7,21],[21,34],[4,11],[28,16],[31,34],[6,39],[31,5],[39,10],[26,32],[22,39],[8,28],[36,32],[15,41],[2,9],[44,26],[44,27],[28,23],[4,34],[35,30],[33,43],[21,40],[37,2],[3,43],[18,9],[17,41],[1,5],[15,34],[6,34],[25,11],[41,29],[1,23],[22,23],[39,38],[42,30],[40,3],[3,32],[40,33],[22,36],[40,26],[18,43],[32,43],[25,3],[29,13],[19,9],[40,18],[25,19],[26,30],[35,27],[41,35],[18,24],[6,2],[0,42],[44,8],[30,28],[28,9],[12,16],[25,30],[7,2],[0,26],[14,29],[21,25],[11,23],[15,24],[11,3],[31,23],[26,33],[35,12],[14,30],[37,36],[3,2],[42,43],[36,33],[0,39],[44,19],[21,36],[7,22],[41,39],[22,13],[8,43],[25,16],[8,13],[44,13],[0,28],[39,28],[6,22],[21,29],[6,17],[22,20],[16,10],[26,11],[8,17],[41,28],[8,37],[36,35],[36,19],[20,25],[15,40],[5,16],[15,4],[20,42],[0,1],[2,23],[0,32],[44,41],[44,28],[17,3],[35,32],[4,19],[22,34],[18,29],[26,24],[44,30],[26,16],[25,28],[41,23],[40,16],[16,9],[39,9],[21,32],[0,14],[17,30],[20,43],[4,38],[24,19],[25,24],[7,9],[4,24],[37,12],[22,32],[29,34],[20,5],[1,12],[4,12],[6,10],[23,9],[36,27],[25,9],[21,35],[3,10],[30,19],[8,30],[26,19],[1,18],[37,9],[6,41],[28,13],[37,3],[37,30],[14,37],[20,14],[31,11],[12,9],[25,33],[26,28],[4,13],[10,34],[35,38],[21,30],[14,27],[4,41],[7,32],[6,12],[22,33],[18,27],[31,40],[5,35],[5,30],[40,30],[37,18],[12,2],[18,36],[6,36],[8,4],[4,37],[20,1],[18,5],[8,23],[7,28],[17,42],[38,43],[19,13],[15,22],[16,13],[37,32],[25,38],[18,13],[5,38],[39,16],[41,22],[20,34],[4,14],[38,33],[37,16],[40,43],[41,2],[44,7],[17,36],[26,23],[37,33],[15,32],[39,21],[24,38],[32,13],[8,15],[44,17],[10,33],[6,23],[25,34],[14,23],[5,12],[21,3],[40,9],[0,30],[3,19],[22,19],[1,16],[30,24],[7,40],[20,13],[6,16],[21,9],[15,1],[7,30],[42,19],[42,12],[4,16],[25,2],[15,16],[22,11],[14,18],[29,19],[38,2],[41,36],[15,14],[6,24],[14,12],[20,24],[29,27],[4,0],[36,23],[17,13],[44,33],[44,23],[42,36],[18,19],[26,9],[27,24],[8,35],[8,3],[38,32],[22,10],[25,10],[0,29],[39,32],[32,34],[0,40],[20,28],[14,43],[21,33],[28,27],[12,28],[31,13],[7,23],[25,42],[31,27],[27,9],[44,11],[40,2],[39,43],[17,10],[17,21],[30,10],[7,29],[4,32],[15,11],[14,34],[22,35],[22,21],[35,9],[25,37],[21,1],[18,3],[7,25],[17,38],[6,4],[6,40],[20,10],[19,23],[6,0],[14,36],[41,12],[1,37],[31,30],[31,35],[15,2],[35,28],[41,25],[8,19],[10,43],[37,42],[37,28],[26,43],[29,2],[31,33],[0,3],[8,14],[43,9],[2,34],[0,21],[41,26],[11,2],[44,25],[26,12],[15,20],[24,34],[41,11],[6,27],[7,26],[36,38],[8,27],[41,34],[4,23],[17,22],[14,2],[6,21],[1,38],[6,26],[21,13],[21,5],[2,32],[14,42],[0,24],[39,3],[37,29],[37,5],[38,13],[25,1],[44,24],[5,33],[6,13],[3,29],[42,16],[3,27],[18,30],[0,38],[11,28],[14,40],[7,19],[15,33],[36,10],[8,9],[29,38],[8,40],[38,23],[1,30],[1,28],[41,10],[25,5],[3,38],[36,11],[44,21],[7,43],[36,12],[6,25],[44,5],[37,27],[42,27],[1,11],[26,27],[22,24],[3,13],[36,29],[2,43],[7,33],[20,9],[15,18],[40,27],[4,18],[0,18],[8,21],[31,20],[20,26],[4,39],[5,43],[14,24],[4,35],[28,10],[39,24],[6,31],[4,22],[0,16],[4,29],[1,35],[8,20],[8,11],[17,7],[25,18],[11,13],[16,19],[4,5],[40,19],[40,42],[3,23],[16,32],[27,16],[26,10],[25,23],[8,22],[33,19],[12,23],[2,13],[7,0],[41,24],[5,24],[44,3],[18,2],[16,33],[0,11],[20,19],[35,2],[41,13],[27,19],[8,41],[42,35],[7,35],[42,24],[28,29],[18,34],[26,42],[0,9],[4,36],[12,32],[44,0],[20,2],[30,13],[36,34],[22,9],[30,23],[37,23],[14,11],[3,24],[34,23],[39,1],[30,12],[6,14],[4,25],[31,1],[37,13],[34,9],[18,42],[7,27],[44,32],[15,12],[11,32],[18,12],[40,10],[4,28],[21,38],[15,35],[25,12],[37,34],[31,7],[6,3],[10,9],[22,37],[30,33],[39,36],[21,2],[20,12],[0,20],[4,7],[33,13],[21,24],[18,33],[29,16],[1,27],[22,3],[0,12],[26,3],[3,33],[11,30],[4,26],[6,7],[44,36],[7,42],[28,33],[22,1],[27,38],[7,12],[43,19],[3,30],[15,37],[31,16],[1,42],[44,42],[0,36],[12,34],[1,36],[31,38],[22,25],[1,26],[39,26],[5,29],[7,1],[17,31],[37,24],[14,9],[20,40],[15,29],[7,3],[17,34],[25,13],[0,2],[41,14],[37,38],[41,7],[6,19],[44,2],[31,10],[37,26],[8,1],[5,2],[15,26],[40,24],[20,3],[44,35],[34,19],[31,32],[12,24],[26,2],[15,17],[31,42],[14,16],[39,23],[4,10],[35,34],[11,27],[6,43],[25,27],[24,16],[40,34],[41,43],[6,30],[1,13],[22,5],[17,43],[10,19],[0,25],[1,33],[42,9],[8,29],[18,11],[20,39],[17,28],[21,11],[27,43],[12,43],[39,13],[31,14],[39,42],[37,10],[2,19],[12,38],[8,42],[3,28],[39,27],[30,2],[37,43],[44,31],[31,21],[14,26],[42,11],[44,10],[10,23],[7,18],[42,10],[17,19],[35,10],[12,33],[17,14],[0,13],[5,3],[22,26],[1,43],[8,12],[7,5],[21,14],[39,18],[11,10],[7,11],[41,20],[15,9],[11,24],[39,34],[7,39],[17,39],[21,43],[44,15],[28,19],[39,30],[22,42],[0,33],[15,30],[21,16],[31,39],[35,29],[6,9],[3,34],[42,3],[4,9],[40,37],[31,2],[14,35],[6,38],[17,23],[21,28],[43,23],[8,16],[41,33],[11,43],[22,43],[36,30],[4,33],[39,2],[41,30],[24,9],[8,18],[1,34],[39,12],[39,29],[30,27],[21,42],[27,23],[21,26],[30,16],[44,34],[17,27],[8,6],[41,18],[39,25],[20,29],[8,39],[6,32],[39,19],[42,33],[41,38],[41,21],[20,35],[41,42],[15,43],[20,16],[35,16],[4,2],[20,32],[15,19],[15,13],[14,10],[44,22],[17,20],[26,5],[33,2],[21,27],[31,0],[6,37],[29,9],[41,16],[0,34],[20,38],[31,29],[5,23],[11,29],[4,17],[41,19],[15,21],[26,36],[40,32],[31,43],[4,27],[4,30],[44,12],[0,19],[6,35],[10,32],[1,19],[7,16],[17,26],[30,38],[36,2],[40,13],[42,13],[29,32],[40,1],[44,16],[14,1],[11,33],[4,1],[29,24],[39,35],[14,33],[5,32],[29,43],[7,37],[27,13],[40,38],[14,5],[24,2],[41,37],[24,10],[44,20],[11,16],[33,23],[32,9],[20,36],[28,24],[11,38],[12,27],[42,23],[20,37],[39,37],[22,29],[21,37],[7,10],[1,32],[42,34],[6,20],[3,16],[25,36],[8,33],[5,9],[40,5],[41,32],[36,9],[28,34],[14,3],[41,9],[8,0],[22,27],[22,18],[31,37],[39,14],[12,10],[32,19],[22,28],[35,24],[20,23],[38,9],[10,2],[17,18],[14,38],[1,2],[28,2],[42,29],[28,32],[21,18],[15,38],[3,35],[1,10],[17,32],[18,23],[41,31],[23,13],[17,11],[40,28],[41,3],[33,9],[25,26],[20,18],[38,34],[17,35],[15,27],[31,9],[40,11],[17,16],[15,42],[8,36],[39,40],[8,38],[41,0],[0,43],[42,38],[25,35],[25,43],[33,32],[4,42],[35,33],[40,35],[6,33],[31,26],[25,40],[4,43],[18,10],[5,19],[8,34],[44,1],[14,32],[35,23],[17,37],[36,24],[39,11],[14,19],[44,43],[30,9],[33,34],[18,32],[22,40],[16,38],[7,20],[11,12],[15,25],[7,36],[44,4],[40,29],[4,40],[5,34],[27,33],[39,5],[15,23],[8,32],[36,3],[31,22],[7,34],[36,16],[42,28],[6,42],[37,35],[0,23],[35,19],[31,24],[22,14],[20,21],[27,32],[12,13],[0,22],[44,6],[24,43],[16,2],[44,14],[6,29],[8,7]]
Case 38
n = 100
edges = [[77,54],[54,17],[17,50],[50,52],[52,64],[64,14],[14,81],[81,62],[62,85],[85,61],[61,48],[48,94],[94,45],[45,86],[86,76],[76,28],[28,90],[90,12],[12,10],[10,0],[0,11],[11,8],[8,27],[27,42],[42,15],[15,37],[37,18],[18,47],[47,22],[22,71],[71,78],[78,44],[44,89],[89,72],[72,34],[34,56],[56,25],[25,68],[68,36],[36,67],[67,59],[59,82],[82,49],[49,2],[2,35],[35,58],[58,93],[93,20],[20,98],[98,99],[99,39],[39,5],[5,53],[53,7],[7,95],[95,13],[13,83],[83,66],[66,16],[16,87],[87,33],[33,63],[63,32],[32,60],[60,96],[96,6],[6,65],[65,31],[31,26],[26,80],[80,43],[43,41],[41,21],[21,97],[97,70],[70,19],[19,91],[91,92],[92,3],[3,29],[29,40],[40,4],[4,9],[9,30],[30,84],[84,88],[88,57],[57,69],[69,38],[38,23],[23,73],[73,79],[79,75],[75,55],[55,1],[1,46],[46,51],[51,74],[74,24]]