No.3057 Tree Distance Set
Problem Statement
Takahashi has a tree $T$. $T$ consists of at most $500$ vertices, and each edge has a positive integer weight.
Using the tree $T$, Takahashi performed the following operations.
- Choose some of the vertices of the tree $T$ to form a vertex set $S$.
- For every combination of two distinct vertices chosen from $S$, compute the distance between the two vertices and write each distance on a blackboard. Here, the distance between two vertices is the sum of the weights of the edges on the simple path connecting those two vertices in the tree $T$.
You are given a set $D = \{D_1, D_2, \dots, D_K\}$ consisting of $K$ elements. Each element of $D$ is a positive even number. It is known that every number written on the blackboard is contained in $D$, and that every number contained in $D$ was written on the blackboard at least once.
Find one possible combination of the tree $T$ and the vertex set $S$ created by Takahashi. It can be shown that such a combination of a tree and a vertex set always exists under the constraints of this problem.
Input
$K$ $D_1\ D_2\dots D_K$
- $1 \le K \le 150$
- $2 \le D_i \le 300$
- $D_i$ is even
- If $i \neq j$, then $D_i \neq D_j$
- All inputs are integers
Output
Output one possible combination of the tree $T$ and the vertex set $S$ chosen by Takahashi in the following format.
$N$
$u_1\ v_1\ w_1$
$u_2\ v_2\ w_2$
$\vdots$
$u_{N-1}\ v_{N-1}\ w_{N-1}$
$M$
$S_1\ S_2\dots S_M$
On line $1$, output the number of vertices $N(2 \le N \le 500)$ of the tree $T$.
On each of lines $2$ through $N$, output the information of the $N-1$ edges of the tree $T$, one edge per line. On line $i+1$, output $3$ integers $u_i, v_i, w_i(1 \le u_i, v_i \le N, 1 \le w_i \le 1000)$ separated by spaces. This output means that the $i$-th edge of the tree $T$ bidirectionally connects vertex $u_i$ and vertex $v_i$ with weight $w_i$.
On line $N+1$, output the size $M(2 \le M \le N)$ of the vertex set $S$.
On line $N+2$, output the numbers of the $M$ vertices contained in $S$, separated by spaces. $S_1, S_2 \dots S_M$ must be pairwise distinct integers between $1$ and $N$, inclusive.
Print a newline at the end.Sample
Sample 1
Input
3 6 2 4
Output
4 1 2 2 2 3 2 3 4 2 3 1 2 4
The vertex set is $S = \{1,2,4\}$. The distances for each combination of two distinct vertices chosen from $S$ are as follows.
- The distance between vertex $1$ and vertex $2$ is $2$
- The distance between vertex $2$ and vertex $4$ is $4$
- The distance between vertex $1$ and vertex $4$ is $6$
On the other hand, $S = \{1,4\}$ and $S = \{1,2,3\}$ do not satisfy the conditions.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
tute7627
SPD_9X2