接触codeforces时间不长,也就参加了10场左右。之前有次比赛就出现了wa了一道题,在比赛结束后看测试数据log时,发现出错的那组用例是个超过一万行输入的情况,codeforces上的测试数据无法完全显示,也就没办法复制后台出问题的测试数据,导致想在比赛后纠错却无从下手。昨天(2017.2.2)的比赛时同样遇到了这个情况。题目如下:
Each New Year Timofey and his friends cut down a tree of n vertices and bring it home. After that they paint all the n its vertices, so that the i-th vertex gets color ci.
Now it's time for Timofey birthday, and his mother asked him to remove the tree. Timofey removes the tree in the following way: he takes some vertex in hands, while all the other vertices move down so that the tree becomes rooted at the chosen vertex. After that Timofey brings the tree to a trash can.
Timofey doesn't like it when many colors are mixing together. A subtree annoys him if there are vertices of different color in it. Timofey wants to find a vertex which he should take in hands so that there are no subtrees that annoy him. He doesn't consider the whole tree as a subtree since he can't see the color of the root vertex.
A subtree of some vertex is a subgraph containing that vertex and all its descendants.
Your task is to determine if there is a vertex, taking which in hands Timofey wouldn't be annoyed.
The first line contains single integer n (2 ≤ n ≤ 105) — the number of vertices in the tree.
Each of the next n - 1 lines contains two integers u and v (1 ≤ u, v ≤ n, u ≠ v), denoting there is an edge between vertices u and v. It is guaranteed that the given graph is a tree.
The next line contains n integers c1, c2, ..., cn (1 ≤ ci ≤ 105), denoting the colors of the vertices.
Print "NO" in a single line, if Timofey can't take the tree in such a way that it doesn't annoy him.
Otherwise print "YES" in the first line. In the second line print the index of the vertex which Timofey should take in hands. If there are multiple answers, print any of them.
4 1 2 2 3 3 4 1 2 1 1
YES 2
3 1 2 2 3 1 2 3
YES 2
4 1 2 2 3 3 4 1 2 1 2
NO
提交时在第10组数据时候wa了,日志如下:
100000 87340 49194 81258 30152 86087 63270 76425 3115 81368 24550 41106 6430 51047 52299 14740 86386 92823 35333 67024 59650 96768 68619 27456 11488 32792 95982 43677 37054 75282 7613 47234 66384 71543 59600 78536 6489 78144 39145 69124 51364 24639 8688 15085 19170 16453 481 67647 9259 35951 85203 26487 4366 49744 74957 38281 18679 22466 45365 33692 88671 59478 36493 67718 60463 9085 62331 70558 95039 31913 67340 30581 94343 37007 28436 55767 20381 98969 75359 95703 ...
NO
YES 87340
wrong answer participant hasn't found the solution
开始的时候第一反应是int改成long long,后来发现根本不是这个问题,题中的数据用int完全可以。再思考思考还是没有头绪,凌晨2点左右也困了,就先睡去了。今天思考这个问题时突然想起寝室大牛说的一次acm省赛经历,他在比赛时收到赛方的道歉,承认测试数据的问题,这份道歉是re的一位参赛选手的质疑。这名选手比赛时感觉测试数据超出给定范围,并利用死循环证明了测试数据中确实有问题。(对非法测试数据进行死循环来显示Time Limit...)于是突然想到codeforces的测试数据其实可以不用得到,通过一些手段我可以在网站上直接调试的!观察了一下前9组测试用例,没有一个第二个输入与第10组相同的(87340),果断加了一个判断,若第二个输入为87340,则输出一些我需要的信息,之后的进展很顺利,我利用网站上的输出信息很快就找出了问题所在,最终ac。
这个发现对我来说还是很有价值的,可能之前也有人用过吧,不过自己一步一步探索出来是对我以后看待问题角度的一个提升。