#P10992. [2015杭电多校]Persistent Link/cut Tree
[2015杭电多校]Persistent Link/cut Tree
Persistent Link/cut Tree
Problem Description
Teacher Mai has trees, . consists one vertex numbered . He generated the in this way. Get a copy of and . Add an edge with length between vertex numbered in and in . Relabel the vertices in the new tree. Let be the number of vertices in . He keeps labels of vertices in the same, and adds to labels of vertices in . If there is a tree with vertices , $F(T)=\sum_{i=0}^{n-1} \sum_{j=i+1}^{n-1} d(v_i,v_j)$( means the distance between the and ). For every , he wants to know .
Input
There are multiple test cases(about ). For each test case, the first line contains one number , the following are lines. The -th lines contains five numbers $a_i,b_i,c_i,d_i,l_i(0\leq a_i,b_i<i,0\leq l_i\leq 10^9)$. It's guarenteed that there exists a vertex numbered in and there exists a vertex numbered in .
Output
For each test case, print modulo in the -th line.
Sample Input
3
0 0 0 0 2
1 1 0 0 4
2 2 1 0 3
Sample Output
2
28
216
Author
xudyh
Source
2015 Multi-University Training Contest 9