Hi5 student Interview Question
StudentsCountry: India
I share CodeWithMe 's doubts about this being a graph rather than a tree. Regarding the solution - you mention triplets like (2,3,5) as possible solutions to this problem. In this particular triplet, 2 to 3 is a direct path, but there is no direct path between 3 and 5, instead, one has to go from 3 to 4 and then 4 to 5. If this is a valid answer, then this problem becomes relatively straightforward, just take combinations of ends of a red edge with all the other vertices present and repeat this procedure for all the red edges. Am I missing something here?
i have some doubts abt this problem
- Kavita June 19, 2014if u want that there should exists a path from
Node A to Node B i say its color a
Node B to Node C i say its color b
Node C to Node A i say its color c
if (a == red || b ==red || c ==red) then (A,B,C) is triplet...
if u look a closed walk of size 3 then i think its cannot be tree....trees not have closed path......
i think it can be a graph....
if i take it as graph
then Make all cominations of tree element out of N elements
for each combination check there exists a closed path from a to b , b to c , c to a
if closed paths exists && 1 red edge also then print that combination
plz check is it a tree or graph...i post solution once its confirmed