Logo
(追記) (追記ここまで)

33672번 - Underspecified Ultrametrics 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 2048 MB87787.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:

  • $d(u,v)≥0$ for any two points $u,ドル $v$ with $d(u,v)=0$ if and only if $u=v$
  • $d(u,v)=d(v,u)$ for any two points $u,ドル $v$
  • $d(u,v)≤\max\{d(u,w),d(w,v)\}$ for any three points $u,ドル $v,ドル $w$

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.

제한

예제 입력 1

3 3
0 1 5
0 2 7
1 2 7

예제 출력 1

possibly ultrametric

예제 입력 2

3 3
0 1 5
0 2 7
1 2 5

예제 출력 2

not ultrametric

예제 입력 3

5 5
0 1 10
1 2 11
2 3 12
3 4 13
0 4 12

예제 출력 3

not ultrametric

예제 입력 4

5 5
0 1 10
1 2 11
2 3 12
3 4 13
0 4 13

예제 출력 4

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}$$

예제 입력 5

7 5
0 1 3
4 5 1
0 2 1
1 2 3
4 6 10

예제 출력 5

possibly ultrametric

힌트

출처

University > University of Alberta Programming Contest > UAPC 2025 > Division 1 K번

  • 문제를 만든 사람: Zachary Friggstad
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /