Tree Embedding

시간 제한1초메모리 제한1024 MB

요약
가중치가 있는 트리의 각 정점에 m차원 벡터를 부여해 두 벡터 차의 L-무한대 노름이 두 정점 사이의 트리 거리와 같도록 만든다.
난이도

어려움10점 중 8점

유형
트리, 수학, 기하, 구현
정답자
아직 제출이 없습니다

문제

bobo has a tree with nn vertices. bobo would like to assign an mm-dimension vector p(v)\mathbf{p}(v) to vertex vv, such that for all a,ba, b, dist(a,b)=⟨p(a),p(b)⟩\mathrm{dist}(a, b) = \langle \mathbf{p}(a), \mathbf{p}(b) \rangle.

Note that dist(a,b)\mathrm{dist}(a, b) is the length of the shortest path between vertices aa and bb. For two vectors u=(u_1,u_2,…,u_m)\mathbf{u} = (u\_1, u\_2, \dots, u\_m) and v=(v_1,v_2,…,v_m)\mathbf{v} = (v\_1, v\_2, \dots, v\_m), ⟨u,v⟩=max⁡∣u_1−v_1∣,∣u_2−v_2∣,…,∣u_m−v_m∣\langle \mathbf{u}, \mathbf{v} \rangle = \max\\{|u\_1 - v\_1|, |u\_2 - v\_2|, \dots, |u\_m - v\_m|\\}.

입력

The first line contains an integer nn (2≤n≤10002 \leq n \leq 1000).

Vertices are numbered by 1,2,…,n1, 2, \dots, n for convenience.

Each of the following (n−1)(n - 1) lines contains 33 integers a_i,b_i,c_ia\_i, b\_i, c\_i, which denotes an edge between vertices a_ia\_i and b_ib\_i with length c_ic\_i (1≤a_i,b_i≤n,1≤c_i≤1000001 \leq a\_i, b\_i \leq n, 1 \leq c\_i \leq 100000).

출력

The first line contains an integer mm, which denotes the dimension of vectors (1≤m≤161 \leq m \leq 16).

Each of the following nn lines contains mm integers which denotes the vector p(i)\mathbf{p}(i). The coordinates should be in \[−109,109]\[-10^9, 10^9].

Any appropriate solution will get accepted.

예제2

  1. 예제 1

    입력
    2
    1 2 2
    
    예상 출력
    1
    0
    -2
    
  2. 예제 2

    입력
    4
    1 2 1
    1 3 1
    1 4 1
    
    예상 출력
    2
    0 0
    -1 -1
    -1 1
    1 1