QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 256 MB Total points: 100

#12035. 高维树

統計

九条可怜是一个热爱高维空间(并不)的女孩子。

今天她意外收获了一棵 $n$ 个节点的树,节点的编号从 $1$ 到 $n$,树上每一条边的边权都是 $1$。定义 $d(i,j)$ 为 $i$ 号点和 $j$ 号点在树上的距离。

因为树是生长在三维空间中的,这让可怜很不开心。于是可怜想要把这棵树给塞到一个 $m$ 维空间中。具体来说,可怜想要在 $m$ 维空间中找到 $n$ 个点 $x_1, \dots,x_n$,其中第 $i$ 个点的坐标是 $(x_{i,1}, \dots, x_{i,m})$。定义 $x_i$ 和 $x_j$ 的距离是 $\sum_{k=1}^m |x_{i,k}-x_{j,k}|$,即我们平时常说的曼哈顿距离。可怜希望对所有的编号对 $(i,j)$,$x_i$ 和 $x_j$ 的距离就是 $d(i,j)$。

然而维护一个高维空间是非常花时间和经历的,即使对可怜来说也一样。因此可怜想要找到最小的 $m$,使得她可以找到满足条件的 $n$ 个点。

输入格式

第一行输入一个正整数 $n(n>1)$,表示节点个数。

接下来 $n-1$ 行,每行两个整数 $i,j$ 表示树上的一条边。

输出格式

如果不存在小于等于 $100$ 的满足条件的 $m$,则输出一行一个整数 $-1$。

否则第一行输出一个正整数 $m(1 \leq m \leq 100)$,表示满足条件的最小的空间维数。

接下来 $n$ 行每行输出 $m$ 个空格隔开的整数 $x_{i,j}$,表示第 $i$ 个点的坐标,你需要保证 $|x_{i,j}| \leq 100$。

如果存在多组解,输出任意一组即可。数据保证如果有解,一定存在 $|x_{i,j}| \leq 100$ 的解。

样例数据

样例 1 输入

5
1 2
1 3
3 4
3 5

样例 1 输出

2
0 0
1 0
-1 0
-1 1
-1 -1

子任务

本题分为 $3$ 个子任务,你需要通过所有子任务中的所有测试点,才能拿到这个子任务的分数:

子任务一($8$ 分),$n \leq 100$,第 $i$ 条边连接了 $1$ 和 $i$。

子任务二($41$ 分),$n \leq 100$,第 $i$ 条边连接了 $\lceil \frac{i}{2} \rceil$ 和 $i+1$。

子任务三($51$ 分),$n \leq 100$。

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.