昨天的 CF 就看了这么一题,写了个题解,补了个证明。
有一说一,这题出的真的很不错,做出来之后感受到了久违的思考 > 解决问题的快乐。Dreamoon NB!
HDU 5963 朋友
传送门:http://acm.split.hdu.edu.cn/showproblem.php?pid=5963 题解 结论题:对于每种情况,只需要计算和根直接相连的权值之后的奇偶即可。 代码
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 |
//while(true) RP++; #include<cstdio> #include<map> #include<iostream> #include<algorithm> #include<cstring> #define mp(x,y) make_pair(x,y) using namespace std; const int Maxn=40000; int sum[Maxn+5]; int n,m; map<pair<int,int>,int> Edge; inline void solve(int T){ memset(sum,0,sizeof(sum)); Edge.clear(); scanf("%d%d",&n,&m); for (int i=1;i<n;i++){ int x,y,z; scanf("%d%d%d",&x,&y,&z); sum[x]+=z; sum[y]+=z; if (x>y) swap(x,y); Edge[mp(x,y)]=z; } for (int i=1;i<=m;i++){ int ord=0; int x,y,z; scanf("%d",&ord); if (ord==0){ scanf("%d",&x); if (sum[x]%2==0) printf("Boys win!\n"); else printf("Girls win!\n"); }else{ scanf("%d%d%d",&x,&y,&z); if (x>y) swap(x,y); if (Edge[mp(x,y)]==z){ }else{ Edge[mp(x,y)]=z; if (z==0){ sum[x]--; sum[y]--; }else{ sum[x]++; sum[y]++; } } } } } int main(){ int T=0; while(scanf("%d",&T)!=EOF) for (int i=1;i<=T;i++) solve(i); return 0; } |