5333: Tree Xor

内存限制:512 MB 时间限制:2.000 S
评测方式:文本比较 命题人:
提交:0 解决:0

题目描述

Bob has a tree with n nodes and the weight of i-th node is wi.
But Bob forgot w1...n, he only remembers wi is an integer in [li,ri] and wu xor wv for each edge (u,v) in the tree.
Now Bob wants to know the number of possible values of w1...n.
XOR means bitwise exclusive OR.

输入

The first line has one integers n.
Then there are n lines, the i-th line has two integers li,ri.
Then there are n−1 lines, each line has three integers u,v,wu xor wv denote the infomation for each edge.
1≤n≤105
0≤li≤ri<230
0≤wu xor wv<230

输出

Output the answer.

样例输入 复制

4
0 7
1 6
2 5
3 4
1 2 0
1 3 7
2 4 6

样例输出 复制

2