Algorithm ACM MIPT-图形存在之谜-示例不清楚

Algorithm ACM MIPT-图形存在之谜-示例不清楚,algorithm,Algorithm,这是关于“图的存在”问题-。有人能解释为什么示例1中没有树,但示例2中有一棵树吗?在这两个示例中,顶点0、1、2和3相互连接。以下是问题陈述和示例,供您参考: 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

这是关于“图的存在”问题-。有人能解释为什么示例1中没有树,但示例2中有一棵树吗?在这两个示例中,顶点0、1、2和3相互连接。以下是问题陈述和示例,供您参考:

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 给你一个图中的距离矩阵。 您应该检查此图形是否可以是一棵树或一组树(森林)。 边长度为0或正整数。 输入:第一行包含顶点数N。 接下来的N行包含矩阵(仅矩阵的左下三角形)。 距离-1对应于无限距离。 输出:输出是或否。如果是,则下一行应包含边列表 树(具有给定距离矩阵的任何树(森林))。 每条边由其两端的两个标识符编码。 顶点标识符是数字0、1、…、N-1。 输入#1 4. 0 1 0 1 1 0 1 1 1 0 输出#1 不 输入#2 5. 0 1 0 2 1 0 3 2 1 0 -1 -1 -1 -1 0 输出#2 对 0 1 1 2 2 3
这个问题并没有很好地从它的本质上解释出来

给定的矩阵不是我们可以得出的图中的边矩阵,而是一个距离矩阵。每个边的权重可能为1,但我不能完全确定是否有非负权重。必须检查矩阵是否可以通过树或森林实现

也就是说,在第一个示例中,所有顶点都是连接的,但第二个示例可以实现图形如下所示:

    Example 2:
    (0) - (1) - (2) - (3)  (4) 
示例1中的图形是

    Example 1:
    (0) - (1) - (2) - (3)
     |_____|_____|     |     
     |     |___________|
     |_________________|

谢谢你指出这个问题的俄语和英语版本之间的差异!俄文版本似乎表明,矩阵给出了最短路径的长度,这似乎使示例更有意义。我们将沿着这些思路进一步思考。