Submission #524308


Source Code Expand

Copy
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		int root=0;
		parent=new int[N];
		XX=new int[N];
		dfs(root,-1,0);
//Console.WriteLine(String.Join(" ",XX));		
//Console.WriteLine(String.Join(" ",parent));		
		Dictionary<int,long> DD=new Dictionary<int,long>();
		for(int i=0;i<N;i++){
			if(DD.ContainsKey(XX[i])==false)DD.Add(XX[i],0);
			DD[XX[i]]+=1;
		}
		
		long ans=0;
		HashSet<int> H=new HashSet<int>();
		foreach(var k in DD.Keys){
			if(H.Contains(k))continue;
			H.Add(k);
			if(DD.ContainsKey(k^X)){
				H.Add(k^X);
				ans+=DD[k]*DD[k^X];
			}
		}
		
		Console.WriteLine(ans);
		
	}
	int N,X;
	List<Pair>[] E;
	int[] parent;
	int[] XX;
	void dfs(int now, int par,int x){
		parent[now]=par;
		XX[now]=x;
		foreach(var v in E[now]){
			if(v.Pos!=par){
				dfs(v.Pos,now,x^v.Cost);
			}
		}
	}
	
	
	
	
	public Sol(){
		var d=ria();
		N=d[0];X=d[1];
		E=new List<Pair>[N];
		for(int i=0;i<N;i++)E[i]=new List<Pair>();
		for(int i=0;i<N-1;i++){
			var dd=ria();
			E[dd[0]-1].Add(new Pair(dd[1]-1,dd[2]));
			E[dd[1]-1].Add(new Pair(dd[0]-1,dd[2]));
		}
	}

	class Pair{
		public int Pos;
		public int Cost;
		public Pair(int pos,int cost){
			Pos=pos;Cost=cost;
		}	
	}


	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(){return Console.ReadLine().Split(' ');}
	static int[] ria(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>int.Parse(e));}
	static long[] rla(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>long.Parse(e));}
	static double[] rda(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>double.Parse(e));}
}

Submission Info

Submission Time
Task C - エックスオア多橋君
User kuuso
Language C# (Mono 3.2.1.0)
Score 0
Code Size 2029 Byte
Status WA
Exec Time 615 ms
Memory 48676 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 100
Status
AC × 3
AC × 24
WA × 3
Set Name Test Cases
Sample subtask0_sample_01.txt, subtask0_sample_02.txt, subtask0_sample_03.txt
All subtask0_sample_01.txt, subtask0_sample_02.txt, subtask0_sample_03.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt, subtask1_17.txt, subtask1_18.txt, subtask1_19.txt, subtask1_20.txt, subtask1_21.txt, subtask1_22.txt, subtask1_23.txt, subtask1_24.txt
Case Name Status Exec Time Memory
subtask0_sample_01.txt AC 147 ms 11080 KB
subtask0_sample_02.txt AC 146 ms 11056 KB
subtask0_sample_03.txt AC 148 ms 11140 KB
subtask1_01.txt WA 152 ms 11028 KB
subtask1_02.txt WA 153 ms 11640 KB
subtask1_03.txt AC 613 ms 45168 KB
subtask1_04.txt AC 615 ms 45108 KB
subtask1_05.txt AC 613 ms 45108 KB
subtask1_06.txt WA 436 ms 48676 KB
subtask1_07.txt AC 501 ms 34848 KB
subtask1_08.txt AC 515 ms 34852 KB
subtask1_09.txt AC 537 ms 36788 KB
subtask1_10.txt AC 524 ms 36668 KB
subtask1_11.txt AC 154 ms 11640 KB
subtask1_12.txt AC 152 ms 11648 KB
subtask1_13.txt AC 510 ms 34904 KB
subtask1_14.txt AC 543 ms 34900 KB
subtask1_15.txt AC 235 ms 17736 KB
subtask1_16.txt AC 199 ms 17756 KB
subtask1_17.txt AC 195 ms 17796 KB
subtask1_18.txt AC 254 ms 17824 KB
subtask1_19.txt AC 241 ms 17740 KB
subtask1_20.txt AC 250 ms 17800 KB
subtask1_21.txt AC 242 ms 17748 KB
subtask1_22.txt AC 195 ms 17796 KB
subtask1_23.txt AC 188 ms 17832 KB
subtask1_24.txt AC 189 ms 17788 KB