HDU 5963 博弈

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

题目大意:中文题

思路:看ICPC camp好了,简单易懂:https://async.icpc-camp.org/d/628-2016     上面的C题

//看看会不会爆int!数组会不会少了一维!
//取物问题一定要小心先手胜利的条件
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker,"/STACK:102400000,102400000")
#define LL long long
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define haha printf("haha\n")
const int maxn = + ;
struct Node{
int to, val;
};
vector<Node> G[maxn];
int n, m;
int ans[maxn]; int main(){
int t; cin >> 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, val;
scanf("%d%d%d", &u, &v, &val);
G[u].pb(Node{v, val}); G[v].pb(Node{u, val});
}
memset(ans, , sizeof(ans));
for (int i = ; i <= n; i++){
for (int j = ; j < G[i].size(); j++){
ans[i] += G[i][j].val;
}
}
for (int i = ; i <= m; i++){
int ty; scanf("%d", &ty);
if (ty == ){
int root; scanf("%d", &root);
if (ans[root] % ) printf("Girls win!\n");
else printf("Boys win!\n");
}
else if (ty == ){
int u, v, val;
scanf("%d%d%d", &u, &v, &val);
for (int j = ; j < G[u].size(); j++){
if (G[u][j].to == v){
if (val == G[u][j].val) break;
else {
G[u][j].val = val;
if (val == ) ans[u]++, ans[v]++;
else ans[u]--, ans[v]--;
}
}
}
for (int j = ; j < G[v].size(); j++){
if (G[v][j].to == u){
G[v][j].val = val;
break;
}
}
}
}
}
return ;
}
上一篇:Linux查看硬件信息以及驱动设备的命令


下一篇:IT咨询顾问:一次吐血的项目救火 java或判断优化小技巧 asp.net core Session的测试使用心得 【.NET架构】BIM软件架构02:Web管控平台后台架构 NetCore入门篇:(十一)NetCore项目读取配置文件appsettings.json 使用LINQ生成Where的SQL语句 js_jquery_创建cookie有效期问题_时区问题