CF1007D.Ants
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There is a tree with n vertices. There are also m ants living on it. Each ant has its own color. The i -th ant has two favorite pairs of vertices: ( ai,bi ) and ( ci,di ). You need to tell if it is possible to paint the edges of the tree in m colors so that every ant will be able to walk between vertices from one of its favorite pairs using only edges of his color; if it is possible, you need to print which pair every ant should use.
输入格式
The first line contains a single integer n ( 2≤n≤105 ) — the number of vertices.
Each of the next n−1 lines contains two integers ui and vi ( 1≤ui,vi≤n ), meaning that there is an edge between vertices ui and vi .
The next line contains a single integer m ( 1≤m≤104 ) — the number of ants.
Each of the next m lines contains four integers ai , bi , ci , and di ( 1≤ai,bi,ci,di≤n , ai=bi,ci=di ), meaning that pairs ( ai , bi ) and ( ci , di ) are favorite for the i -th ant.
输出格式
Print "NO" (without quotes) if the wanted painting is impossible.
Otherwise, print "YES" (without quotes). Print m lines. On the i -th line, print 1 if the i -th ant will use the first pair and 2 otherwise. If there are multiple answers, print any.
输入输出样例
输入#1
6 1 2 3 1 4 1 5 2 6 2 3 2 6 3 4 1 6 6 5 1 4 5 2
输出#1
YES 2 1 2
输入#2
5 1 2 1 3 1 4 1 5 2 2 3 4 5 3 4 5 2
输出#2
NO
说明/提示
In the sample, the second and the third edge should be painted in the first color, the first and the fifth should be painted in the second color, and the fourth should be painted in the third color.