F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

WO MEI K

Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 222    Accepted Submission(s): 95


Problem Description
There is a weighted tree with $n$ vertices and $n-1$ edges. each edge has a value. Let $f(v,u)$ be the number of values that appear exactly once on the edges of a simple path between vertices $v$ and $u$.

Now you randomly choose $k$ vertices, which is $x_1,x_2,\dots,x_k$. For all $k=1,2,\dots,n$, calculate the expectation of $e_k=\sum_{i=1}^{k}\sum_{j=i+1}^{k}f(x_i,x_j)$ modulo $998244353$
 

Input
This problem contains multiple test cases.The first line of input contains a single integer $t (1 \leq t \leq 2 \cdot 10^{5})$---the number of test cases.The description of test cases follows.

In a test, the first line contains a single integer $n$ ($2 \leq n \leq 2 \cdot 10^{5}$) --- the number of island

Each of the next $n-1$ lines contains three integers $v , u$ and $x$ ($1 \leq v,u,x \leq n$) --- This means that this egde connects $u$ and $v$, and the value of this edge is $x$.

It's guarantee the sum of $n$ over all test cases doesn't exceed $10^{6}$.
 

Output
For each test case, print a single value $X=e_1\oplus e_2\oplus\dots \oplus e_n$, where the note $\oplus$ denotes XOR by bit.
 

Sample Input
2 2 1 2 1 3 1 2 1 1 3 2
 

Sample Output
1 332748115
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-26 07:09:05, Gzip enabled