Problem C. Problem C. Problems on a Tree
时间限制 1000 ms
内存限制 256 MB
Kazari loves to solve math problems.
In her opinion, all problems can be divided into three categories according to their difficulties - Easy, Medium and Hard, represented as $1, 2$ and $3$, respectively.
Today she goes to the forest and finds a strange tree with $n$ vertices: there is a problem on each edge!
Formally, the $i$-th edge on the tree directly connects vertex $u_i$ and $v_i$ and contains a math problem which belongs to $c_i$ category.
She makes a decision that she will
choose two endpoints $s, t$ and walk from $t$ to $s$ on each of next $m$ days. During her walk, she must solve all problems that she will go through, but unfortunately, not on all days she will be able to do that - because the problems may be too hard!
More precisely, Kazari is able to solve all categories of problems at the beginning of a day, however, once she solve a Hard problem, she will lose all her faith at once, in the rest of the day she is only able to solve Easy problems, i.e., if she is encountered with a Medium or Hard problem during this time, she will fail.
There is a piece of good news that on each morning of next $m$ days, exactly one problem will be chosen to become easier, i.e., a Hard problem will become a Medium problem, a Medium problem will become a Easy problem, a Easy problem will remain the same. Note that the effect is persistent.
Kazari would like to know, for each day,
whether she is able to reach $s$ from $t$ and
how many vertices from which she is able to reach $s$ among all $n$ vertices.
输入数据
输出数据
For each test case, print two integers for each day, the first integer denotes whether the girl is able to reach $s$ and the second integer denotes the number of vertices from which she is able to reach $s$.
样例输入
复制
1
6 5
1 2 3
2 3 3
1 4 3
3 5 3
2 6 3
2 6 1 5
3 5 2 4
2 3 4 4
2 3 2 4
1 2 6 2
样例输出
$ Mathjax font initiator $