This is with reference to the ‘graph existence’ problem – http://acm.mipt.ru/judge/problems.pl?problem=110. Can someone explain why there is no tree in example 1 but there is a tree in example 2? In both examples, vertices 0, 1, 2 and 3 are connected to each other. Here is the problem statement and examples for your reference:
You are given a matrix of distances in a graph. You should check whether this graph could be a tree or set of trees (forest). Edge length is 0 or positive integer. Input: The first line contains number of vertices N. Next N lines contains matrix (only left bottom triangle of matrix). Distance -1 corresponds to infinite distance. Output: Output YES or NO. If YES, then next lines should contains list of edges of the tree (any tree (forest) with given distance matrix). Each edge is coded by two identifiers of it's ends. Vertex identifiers are numbers 0, 1, ..., N-1. Input#1 4 0 1 0 1 1 0 1 1 1 0 Output#1 NO Input#2 5 0 1 0 2 1 0 3 2 1 0 -1 -1 -1 -1 0 Output#2 YES 0 1 1 2 2 3
The problem is not very well translated from its Russian original.
The given matrix is not the matrix of edges in the graph as one might conclude, but a distance matrix. Each edge
probably has weight of 1, but I am not entirely surehas a nonnegative weight. One has to check if the matrix can be realized by a tree or a forest.That is in the first example all vertices are connected, but the second example can be realized the graph looks like:
The graph in example 1 is