Hdu 5606 Tree (and collection)

Source: Internet
Author: User

Problem Descriptionthere is a tree (the tree is a connected graph which containsNPoints andn−1 edges), the points is labeled from 1 toN, which edge have a weight from 0 to 1,for every point i∈[< Span id= "MATHJAX-SPAN-17" class= "mn" >1 n] , you should find the number of the points which is closest to It,the clostest points can Contain   i  itself.

Inputthe First line contains a number T,means T test cases.
For all test case,the first line is a NubmerN, means the number of the Points,next n-1 Lines,each line contains three numbersu,v,w , which shows an edge and its weight.
T≤50,N≤5,u,v∈[1,n],w∈[0,1 ]

Outputfor each test case,you need to print the answer to each point.
In consideration of the large output,imagineansi Is the answer to pointINeed to output,ANS1XORANs2 xor ans3.. ansn .

Sample Input131 2 02 3 1

Sample output1in the sample. $ans _1=2$ $ans _2=2$ $ans _3=1$$2~xor~2~xor~1=1$,so You need to output 1.


1 #pragmaComment (linker, "/stack:1024000000,1024000000")2#include <iostream>3#include <cstdio>4#include <cstring>5#include <cmath>6#include <math.h>7#include <algorithm>8#include <queue>9#include <Set>Ten#include <bitset> One#include <map> A#include <vector> -#include <stdlib.h> - using namespacestd; the #definell Long Long - #defineEPS 1e-10 - #defineMOD 1000000007 - #defineN 100006 + #defineINF 1e12 - intN; + intFa[n]; A intNum[n]; at voidinit () { -      for(intI=0; i<n;i++){ -fa[i]=i; -     } - } - intFindintx) { in     returnfa[x]==x?x:fa[x]=find (Fa[x]); - } to voidMergeintXinty) { +     introot1=find (x); -     intRoot2=find (y); the     if(ROOT1==ROOT2)return; *fa[root1]=Root2; $ }Panax Notoginseng intMain () - { the     intT; +scanf"%d",&t); A      while(t--){ the init (); +scanf"%d",&n); -          for(intI=0; i<n-1; i++){ $             inta,b,c; $scanf"%d%d%d",&a,&b,&c); -             if(c==0){ - merge (A, b); the             } -         }Wuyi          thememset (NUM,0,sizeof(num)); -          for(intI=1; i<=n;i++){ Wu             intR=find (i); -num[r]++; About         } $         intans=0; -          for(intI=1; i<=n;i++){ -Ans= (ans^Num[find (i)]); -         } Aprintf"%d\n", ans); +     } the     return 0; -}
View Code

Hdu 5606 Tree (and collection)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.