QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 1024 MB Total points: 100

#9607. 熟练

Statistics

给定大小为 $n$ 的树和 $m$ 条树上的简单路径。你需要给每条路径分配一个颜色 $c_i$,使得任意两条颜色相同的路径,不经过相同的点。

求最少需要几种颜色,并构造方案。

输入格式

本题有多组测试数据。

输入的第一行包含一个整数 $c$,表示子任务编号。$c=0$ 表示该测试点为样例。

输入的第二行包含一个整数 $t$,表示测试数据组数。

接下来依次输入每组测试数据,对于每组测试数据:

输入的第一行包含两个正整数 $n, m$。

接下来 $n-1$ 行,第 $i$ 行包含两个正整数 $u_i, v_i$,表示树的第 $i$ 条边为 $(u_i, v_i)$。

接下来 $m$ 行,第 $i$ 行包含两个正整数 $a_i, b_i$,表示第 $i$ 条路径为 $a_i$ 到 $b_i$ 的简单路径。

输出格式

对于每组测试数据:

第一行包含一个正整数 $k$,表示最少需要几种颜色。

第二行包含 $m$ 个正整数,第 $i$ 个数为第 $i$ 条链的颜色 $c_i$,你需要保证 $1 \le c_i \le k$。

如果你输出的 $k$ 正确,$c_i$ 序列符合格式但不符合题目要求,可以获得该测试点 $15\%$ 的分数。

样例

输入

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

输出

3  
1 2 3  
4  
1 2 3 4  
2  
1 1 2

数据范围

对于所有数据,$1 \le t \le 10^5, 1 \le n, m, \sum n, \sum m \le 5 \times 10^5, 1 \le u_i, v_i, a_i, b_i \le n$。

  • subtask1 (3 pts):$n, m \le 5$。
  • subtask2 (14 pts):$m \le 5$。
  • subtask3 (9 pts):$\forall 1 \le i < n, u_i = i, v_i = i+1$。
  • subtask4 (20 pts):$n, m \le 1000, \sum n, \sum m \le 5000$。
  • subtask5 (22 pts):$\sum n, \sum m \le 10^5$。
  • subtask6 (32 pts):无特殊限制。
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.