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 = 40000 + 5;
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 = 1; i <= n; i++) G[i].clear();
        for (int i = 1; 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, 0, sizeof(ans));
        for (int i = 1; i <= n; i++){
            for (int j = 0; j < G[i].size(); j++){
                ans[i] += G[i][j].val;
            }
        }
        for (int i = 1; i <= m; i++){
            int ty; scanf("%d", &ty);
            if (ty == 0){
                int root; scanf("%d", &root);
                if (ans[root] % 2) printf("Girls win!\n");
                else printf("Boys win!\n");
            }
            else if (ty == 1){
                int u, v, val;
                scanf("%d%d%d", &u, &v, &val);
                for (int j = 0; 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 == 1) ans[u]++, ans[v]++;
                            else ans[u]--, ans[v]--;
                        }
                    }
                }
                for (int j = 0; j < G[v].size(); j++){
                    if (G[v][j].to == u){
                        G[v][j].val = val;
                        break;
                    }
                }
            }
        }
    }
    return 0;
}
View Code

 

posted @ 2016-11-07 11:17  知る奇迹に  阅读(293)  评论(0编辑  收藏  举报