| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 2 초 | 2048 MB | 8 | 7 | 7 | 87.500% |
Given a set of points $X$ with distances $d(u,v)$ between any $u,v \in X,ドル we say that $(X,d)$ is an ultrametric if the following properties are satisfied:
That is, distances in an ultrametric satisfy a slightly stronger property than the usual triangle inequality $d(u,v)≤d(u,w)+d(w,v)$.
You have measured distances between some pair of points from some set $X$ 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 $N$ (3ドル≤N≤100,000円$) and $M$ (0ドル≤M≤400,000円$) where $N$ is the number of points in the set $X$ and $M$ is the number of distances you have determined so far. The points are numbered from 0ドル$ to $N-1$.
Then $M$ lines follow, each containing three integers $u,ドル $v,ドル $l$ (0ドル≤u<v<N$ and 1ドル≤l≤10^9$) where $u,ドル $v$ are two points in $X$ and $l$ is the distance $d(u,v)$ 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 $(X,d')$ where the distances satisfy $d'(u,v)=d(u,v)$ for any $u,v \in X$ such that one of the $M$ given distances you have already determined is for the pair $(u,v)$. Otherwise, output the message not ultrametric.
3 3 0 1 5 0 2 7 1 2 7
possibly ultrametric
3 3 0 1 5 0 2 7 1 2 5
not ultrametric
5 5 0 1 10 1 2 11 2 3 12 3 4 13 0 4 12
not ultrametric
5 5 0 1 10 1 2 11 2 3 12 3 4 13 0 4 13
possibly ultrametric
The following matrix, whose rows and columns are indexed from 0ドル$ to 4ドル,ドル specifies distances that form an ultrametric and agrees with the distances given in the input for this case.
$$\begin{pmatrix}0&10&11&12&13&\10円&0&11&12&13&\11円&11&0&12&13&\12円&12&12&0&13\13円&13&13&13&0 \end{pmatrix}$$
7 5 0 1 3 4 5 1 0 2 1 1 2 3 4 6 10
possibly ultrametric
University > University of Alberta Programming Contest > UAPC 2025 > Division 1 K번