/TreeWithAnExtraEdge

Reads in the edges of a tree that has had a single edge added, and returns an edge that can be removed that will result in a tree

Primary LanguageJava

Project Description

Reads in the edges of a tree that has had a single edge added, and returns an edge that can be removed that will result in a tree.

The method findCutEdge reads in an int[][] which will contain n pairs of numbers. Each number in the n pairs will be between 0 and n − 1, and will indicate an edge in the graph, which is a tree with a single edge added. The method findCutEdge returns an int[] which will be a pair of numbers, corresponding to an edge in the cycle. (Thus, if that edge is cut, a tree remains)

Sample Outputs

Example 1. One sample input is {{0, 1}, {1, 2}, {1, 3}, {1, 4}, {4, 5}, {3, 5}, {5, 6}}

  • Valid outputs for this input are any of: {1, 3}, {1, 4}, {4, 5} or {3, 5}

Example 2. One sample input is {{0, 1}, {1, 2}, {1, 3}, {2, 3}, {4, 5}, {3, 5}, {5, 6}} , which corresponds to the following:

  • Valid outputs for this input are any of: {1, 2}, {1, 3}, or {2, 3}.

Example 3. One sample input is {{0, 1}, {1, 2}, {1, 3}, {2, 6}, {4, 5}, {3, 5}, {5, 6}} , which corresponds to the following:

  • Valid outputs for this input are any of: {1, 2}, {1, 3}, {2, 6}, {3, 5}, or {5, 6}