Underspecified Ultrametrics
시간 제한2초메모리 제한2048 MB
일부 점 쌍의 거리만 주어졌을 때, 나머지 거리를 채워 전체 집합이 초거리 공간이 되도록 만들 수 있는지 판정한다.
문제
Given a set of points with distances between any , we say that is an ultrametric if the following properties are satisfied:
- for any two points , with if and only if
- for any two points ,
- for any three points , ,
That is, distances in an ultrametric satisfy a slightly stronger property than the usual triangle inequality .
You have measured distances between some pair of points from some set and start to wonder if you might be looking at an ultrametric. Write a program to help you determine if this is the case!
입력
The first line of input contains two integers () and () where is the number of points in the set and is the number of distances you have determined so far. The points are numbered from to .
Then lines follow, each containing three integers , , ( and ) where , are two points in and is the distance you have determined between these points. No pair of points will have their distance specified on more than on line.
출력
Output possibly ultrametric if there is an ultrametric where the distances satisfy for any such that one of the given distances you have already determined is for the pair . Otherwise, output the message not ultrametric.