http://acm.hdu.edu.cn/showproblem.php?pid=5963

题意:

思路:

我们可以先只考虑单链,自己试几种案例就可以发现规律,只有与根相连的边为1时,只需要奇数次操作,也就是1次就可以,而别的都需要偶数次操作才能把这条链上的边权全变成0,次数为$2^{n-1}$,n为边的层数。所以我们只要统计与根相连的有多少条权值为1的边即可。

需要改权值的时候搜索一下找到边然后修改。

 #include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int,int> pll;
const int INF = 0x3f3f3f3f;
const int maxn=+; int n, m;
vector<pll> G[maxn]; bool judge(int root)
{
int tmp=;
for(int i=;i<G[root].size();i++)
{
int v=G[root][i].first;
if(G[root][i].second==) tmp++;
}
if(tmp&) return true;
else return false;
} int main()
{
//freopen("in.txt","r",stdin);
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++) G[i].clear();
for(int i=;i<n;i++)
{
int u,v,w;
scanf("%d%d%d",&u,&v,&w);
G[u].push_back(make_pair(v,w));
G[v].push_back(make_pair(u,w));
}
while(m--)
{
int op, root;
scanf("%d",&op);
if(op==)
{
scanf("%d",&root);
if(judge(root)) puts("Girls win!");
else puts("Boys win!");
}
else
{
int u,v,w;
scanf("%d%d%d",&u,&v,&w);
for(int i=;i<G[u].size();i++)
{
int vv=G[u][i].first;
if(vv==v) {G[u][i].second=w;break;}
}
for(int i=;i<G[v].size();i++)
{
int uu=G[v][i].first;
if(uu==u) {G[v][i].second=w;break;}
}
}
}
}
return ;
}

最新文章

  1. 在本地计算机无法启动MYSQL服务错误1067进程意外终止
  2. UWP源码——Unit Test
  3. C# 条码标签打印程序,RDLC报表动态显示多条码标签的方法
  4. 16_会话技术_Session
  5. IOS 笔试
  6. 12款免费与开源的NoSQL数据库
  7. python学习笔记3-列表
  8. 不同版本的IDE ,对应的选项 有变化
  9. C++中_cplusplus及Extern &quot;C&quot;的理解
  10. JS--操作DOM树
  11. 404错误处理以及以后缀为action结尾的处理
  12. vue 上传图片 input=file
  13. Saiku的下载与安装(一)
  14. [LeetCode&amp;Python] Problem 292. Nim Game
  15. Hadoop日记系列目录
  16. Picasso处理同一url,但资源变了的情况
  17. #leetcode刷题之路21-合并两个有序链表
  18. Crossing Rivers HDU - 3232 (均匀分布)
  19. Hello Activemq
  20. spring 代理 演变过程

热门文章

  1. jmeter测试手机号码归属地
  2. Mac SVN版本从1.9降到1.8
  3. Bootstrap 网格系统(Grid System)的工作原理 - 媒体查询
  4. OAuth 白话简明教程 1.简述
  5. jQuery Mobile 和 Kendo UI 的比较(转)
  6. C/S模型之命名管道
  7. python3.4学习笔记(十二) python正则表达式的使用,使用pyspider匹配输出带.html结尾的URL
  8. php array 根据value获取key,in_array()判断是否在数组内实例
  9. 访问Hsql .data数据库文件
  10. Docker 的 Web 管理工具 DockerFly