K - Cut 'em all! CodeForces - 982C 给一棵树 求最多能切几条边使剩下的子树都有偶数个节点 如果n是奇数 那么奇数=偶数+奇数 不管怎么切 都会有奇数 直接打印-1 贪心 如果子树中的点是偶数 就可以直接切了 最后答案要减一 因为原来的树也是偶数个节点 会被统计进去 #include <cstdio> #include <vector> #include <algorithm> using namespace std; ; int res…
C. Cut 'em all! time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You're given a tree with nn vertices. Your task is to determine the maximum possible number of edges that can be removed in s…
Cut 'em all! 题意:求删除了边之后,剩下的每一块联通块他的点数都为偶数,求删除的边最多能是多少. 题解:如果n为奇数,直接返回-1,因为不可能成立.如果n为偶数,随意找一个点DFS建树记录下他的子孙+本身的个数.然后再DFS一下,对于每一个点,他的个数为偶数,就把他与父节点的边隔断, cnt++. 最后cnt就是答案. 代码: #include<bits/stdc++.h> using namespace std; #define Fopen freopen("_in.t…
 Cut 'em all! time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You're given a tree with nn vertices. Your task is to determine the maximum possible number of edges that can be removed in suc…
题目:点这里 题目的意思跟所谓的是英雄就下100层一个意思……在T秒内能够下到地面,就可以了(还有一个板与板之间不能超过H高). 接触这题目是在昨晚的训练赛,当时拍拍地打了个贪心+dfs,果断跟我想的一模一样,TLE了. 赛后我在宿舍里修改了好几次……均无果.后来,我大胆地假设,估计是最后两组出问题TLE的..于是我就在程序里,指定在最后两组输出yes或者no,就这样奇葩地AC了…… 我实验了三次,总共有2*2种可能……(差点就觉得人品差到不行了) 终于AC了.当然,平时练习真心不要这样子,但是…
题目描述 题目简述:树版[k取方格数] 众所周知,桂木桂马是攻略之神,开启攻略之神模式后,他可以同时攻略k部游戏. 今天他得到了一款新游戏<XX半岛>,这款游戏有n个场景(scene),某些场景可以通过不同的选择支到达其他场景.所有场景和选择支构成树状结构:开始游戏时在根节点(共通线),叶子节点为结局.每个场景有一个价值,现在桂马开启攻略之神模式,同时攻略k次该游戏,问他观赏到的场景的价值和最大是多少(同一场景观看多次是不能重复得到价值的) “为什么你还没玩就知道每个场景的价值呢?” “我已经…
/* hdu6060[贪心+dfs] 2017多校3*/ #include <bits/stdc++.h> using namespace std; typedef long long LL; int n, k, u, v, c; struct Edge { LL cost; int to; Edge(, ): cost(C), to(T) {} }; vector<Edge> G[]; ]; LL ans = ; void dfs(int u, int fa) { son[u]+…
题目链接: https://cn.vjudge.net/problem/1576783/origin 输入输出: ExamplesinputCopy42 44 13 1outputCopy1inputCopy31 21 3outputCopy-1inputCopy107 18 48 104 76 59 33 52 102 5outputCopy4inputCopy21 2outputCopy0NoteIn the first example you can remove the edge bet…
题目链接 题意:给你一棵树,让你尽可能删除多的边使得剩余所有的联通组件都是偶数大小. 思路:考虑dfs,从1出发,若当前节点的子节点和自己的数目是偶数,说明当前节点和父亲节点的边是可以删除的,答案+1,因为最开始的节点没有父节点,所以最后答案-1 #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mp make_pair #define pb push_back usi…
题意: 给出一棵树,问最多去掉多少条边之后,剩下的连通分量的size都是偶数. 思路: 如果本来就是奇数个点,那么无论去掉多少条边都不可能成立的. 如果是偶数个点,就进行一次dfs,假设一个点的父亲是u,儿子是v,那么可以去掉(u,v)的条件就是v及其子树有偶数个点,任何一条这样的边都是可以去掉的. 所以一边dfs,一边统计答案就可以了. 代码: #include <stdio.h> #include <string.h> #include <algorithm> #i…