HDU 5963 朋友(找规律博弈)

时间:2023-03-09 08:30:10
HDU 5963 朋友(找规律博弈)

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

题意:

HDU 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 ;
}