1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
| #include <cstdio> #include <cctype> #include <algorithm> #include <cstring> #include <iostream> #include <cassert> #include <cmath> using namespace std; typedef long long ll; template <typename _Tp> void read(_Tp &a, char c = 0, int f = 1) { for(c = getchar(); !isdigit(c); c = getchar()) if(c == '-') f = -1; for(a = 0; isdigit(c); a = a * 10 + c - '0', c = getchar()); a *= f; } template <typename _Tp> void write(_Tp a) { if(a < 0) putchar('-'), a = -a; if(a > 9) write(a / 10); putchar(a % 10 + '0'); }
const int N = 4e4 + 5;
int n, m, tot, hd[N], nxt[2 * N], to[2 * N], w[2 * N];
void add(int u, int v, int c) { nxt[++tot] = hd[u], to[hd[u] = tot] = v, w[tot] = c; }
void alter(int u, int v, int c) { for(int e = hd[u]; e != -1; e = nxt[e]) { if(to[e] == v) { w[e] = c; w[e ^ 1] = c; } } }
void init() { tot = -1; memset(hd, -1, sizeof hd); memset(to, 0, sizeof to); memset(w, 0, sizeof w); memset(nxt, -1, sizeof nxt); }
int main() { int T; read(T); while(T--) { init(); read(n), read(m); for(int i = 1; i < n; i++) { int u, v, c; read(u), read(v), read(c); add(u, v, c); add(v, u, c); } while(m--) { int op; read(op); switch(op) { case 0: { int root; read(root); int x = 0; for(int e = hd[root]; e != -1; e = nxt[e]) { x += w[e]; } if(x & 1) puts("Girls win!"); else puts("Boys win!"); break; } case 1: { int u, v, c; read(u), read(v), read(c); alter(u, v, c); break; } } } } return 0; }
|