Under construction

Still being built. Things may change

Tree Embedding

Time limit1sMemory limit1024 MB

Summary
Given a weighted tree, assign each vertex a vector of at most 16 integers so the max coordinate gap between two vectors equals their tree distance.
Level

Hard9 of 10

Topics
Tree, Divide and conquer, Math
Solved
No attempts yet

Problem

bobo has a tree with nn vertices. bobo wants to assign an mm-dimensional vector p(v)\mathbf{p}(v) to each vertex vv so that for all vertices aa and bb, dist(a,b)=⟨p(a),p(b)⟩\mathrm{dist}(a, b) = \langle \mathbf{p}(a), \mathbf{p}(b) \rangle.

dist(a,b)\mathrm{dist}(a, b) is the length of the shortest path between aa and bb. For vectors u=(u1,…,um)\mathbf{u} = (u_1, \dots, u_m) and v=(v1,…,vm)\mathbf{v} = (v_1, \dots, v_m), the inner product is

⟨u,v⟩=max⁡{∣u1−v1∣,∣u2−v2∣,…,∣um−vm∣}.\langle \mathbf{u}, \mathbf{v} \rangle = \max\{|u_1 - v_1|, |u_2 - v_2|, \dots, |u_m - v_m|\}.

Input

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

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

Each of the following n−1n - 1 lines contains three integers aia_i, bib_i, and cic_i, meaning there is an edge between vertices aia_i and bib_i with length cic_i (1≤ai,bi≤n1 \leq a_i, b_i \leq n, 1≤ci≤1000001 \leq c_i \leq 100000).

Output

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

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

Any valid solution is accepted.

Examples2

  1. Example 1

    Input
    2
    1 2 2
    
    Expected output
    1
    0
    -2
    
  2. Example 2

    Input
    4
    1 2 1
    1 3 1
    1 4 1
    
    Expected output
    2
    0 0
    -1 -1
    -1 1
    1 1