HDU 5416 CRB and Tree
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<cmath>
using namespace std;
#define INF 0x3fffffff
typedef long long LL;
const LL maxn = ;
const LL mod = 1e9+; bool vis[maxn];
int k, Head[maxn], n, Max = ;
LL num[maxn];
struct node
{
int e, next, w;
}Edge[maxn*]; void AddEdge(int s,int e,int w)
{
Edge[k].w = w;
Edge[k].e = e;
Edge[k].next = Head[s];
Head[s] = k;
k ++;
} void DFS(int root,int a)
{
vis[root] = true;
num[a] ++;
for(int i=Head[root]; i!=-; i=Edge[i].next)
{
int e = Edge[i].e;
if(vis[e] == true)
continue;
DFS(e, a^Edge[i].w);
}
} int main()
{ int Q, T;
scanf("%d", &T);
while(T--)
{
scanf("%d", &n);
k = ;
memset(Head, -, sizeof(Head));
memset(vis, false, sizeof(vis));
memset(num, , sizeof(num));
for(int i=; i<n-; i++)
{
int s, e, w;
scanf("%d %d %d",&s, &e, &w);
AddEdge(s, e, w);
AddEdge(e, s, w);
}
DFS(, ); scanf("%d", &Q);
while( Q --)
{
int a;
LL ans = ;
scanf("%d", &a);
if(a == )
ans += n;
for(int i=; i<=; i++)
{
if(a == )
ans += num[i]*(num[i]-)/;
else if(i < (a^i) && num[i] && num[a^i])
ans += num[i]*num[a^i];
}
printf("%lld\n", ans);
}
}
return ;
}
HDU 5416 CRB and Tree的更多相关文章
- Hdu 5416 CRB and Tree (bfs)
题目链接: Hdu 5416 CRB and Tree 题目描述: 给一棵树有n个节点,树上的每条边都有一个权值.f(u,v)代表从u到v路径上所有边权的异或值,问满足f(u,v)==m的(u, v) ...
- HDU 5416 CRB and Tree(前缀思想+DFS)
CRB and Tree Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Tot ...
- HDU 5416——CRB and Tree——————【DFS搜树】
CRB and Tree Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...
- hdu 5416 CRB and Tree(2015 Multi-University Training Contest 10)
CRB and Tree Time Limit: 8000/4000 MS (J ...
- HDU 5416 CRB and Tree (2015多校第10场)
欢迎參加--每周六晚的BestCoder(有米!) CRB and Tree Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536 ...
- HDU 5416 CRB and Tree (技巧)
题意:给一棵n个节点的树(无向边),有q个询问,每个询问有一个值s,问有多少点对(u,v)的xor和为s? 注意:(u,v)和(v,u)只算一次.而且u=v也是合法的. 思路:任意点对之间的路径肯定经 ...
- HDOJ 5416 CRB and Tree DFS
CRB and Tree Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Tot ...
- HDU 5416 CBR and tree
#include<bits/stdc++.h> using namespace std; #define for(i,a,b) for(int i=a;i<=b;++i) //T,N ...
- 异或+构造 HDOJ 5416 CRB and Tree
题目传送门 题意:给一棵树,问f (u, v) 意思是u到v的所有路径的边权值的异或和,问f (u, v) == s 的u,v有几对 异或+构造:首先计算f (1, u) 的值,那么f (u, v) ...
随机推荐
- windows10UWP:Segoe MDL2 图标指南
windows10 UWP 开发中,图标的使用非常广泛.为此,微软建议大家使用 Segoe MDL2 Assets 字体来获取图标.Segoe MDL2 Assets 包括了哪里图标,微软在 http ...
- 各种语言HMAC SHA256实现
语言包含: Javascript ,PHP,Java,Groovy,C#,Objective C,Go,Ruby,Python,Perl,Dart,Swift,Rust,Powershell. Jav ...
- 巧用hidden传递参数
- 怎么让自己的java系统使用支付接口
昨天花了好久的时间学习了支付接口的教,我看了前7集,就够用了,大家上网搜索一下传智播客在线支付还不错. 1.一开始有一个form表单 2.这个表单是他帮你写好的,有很多银行,银行的name都是特定的 ...
- opencart 模块开发详解
opencart 模块开发详解 由 xiekanxiyang » 2013年 7月 11日 10:17 pm opencart 将页面分成若干模块, 每个模块可以有多个实例(可能这样说不是很恰当) 每 ...
- iOS7初体验(2)——单元测试
在Xcode 4.6及以前的版本,一直觉得单元测试这部分功能做得很鸡肋,用起来感觉很别扭.这一次Xcode 5.0默认就引入了单元测试,赶快来看看看相比以前的版本有什么提升吧!~_~ 1. 首 ...
- 浅析CSS中的haslayout
作为一名web开发人员,最大的希望不是自己的水平有多高,而是希望浏览器厂家能够统一标准,相信任何一个只要是接触过web程序开发的人员都有那样的感受,就是浏览器之间的兼容性问题总是让我们的工作平添诸多的 ...
- 【HDU3487】【splay分裂合并】Play with Chain
Problem Description YaoYao is fond of playing his chains. He has a chain containing n diamonds on it ...
- javascript-处理XML
/** * Created by Administrator on 2015/4/4. */ var XmlUtil=(function () { var createDocument= functi ...
- js作用域与作用域链
一直对Js的作用域有点迷糊,今天偶然读到JavaScript权威指南,立马被吸引住了,写的真不错.我看的是第六版本,相当的厚,大概1000多页,Js博大精深,要熟悉精通需要大毅力大功夫. 一:函数作用 ...