http://poj.org/problem?id=2599 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<vector> using namespace std; int n,k,pos; vector<]; ]; int dfs(int k) { ;i<g[k].size();i++) { int t=g[k][…
本文出自   http://blog.csdn.net/shuangde800 -------------------------------------------------------------------------------------- 题目链接:poj-3140 题目 给n个节点的带权树,删掉其中一边,就会变成两颗子树,    求删去某条边使得这这两颗子树的权值之差的绝对值最小. 思路 直接dfs一次,计算所有子树的权值总和tot[i]    如果删掉一条边(v, fa),fa…
http://poj.org/problem?id=2425 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; struct node { int to,next; }e[]; ],Ecou; ]; void add_edge(int u,int v) { e[Ecou].to=v; e[Ecou].next=head[…
也就是转换到树形删边游戏,详见 https://wenku.baidu.com/view/25540742a8956bec0975e3a8.html #include<iostream> #include<cstdio> #include<cstring> using namespace std; const int N=1005; int T,n,m,cnt,h[N],w[N],s[N],top; bool v[N],ve[N]; struct qwe { int n…
Annoying problem 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5293 Description Coco has a tree, whose vertices are conveniently labeled by 1,2,-,n. There are m chain on the tree, Each chain has a certain weight. Coco would like to pick out some ch…
题意: 输入一个整数n,表示有n组测试数据, 每组第一行输入一个整数x表示该组测试一共有x页,接下来输入x行,每行表示一页, 每页或者以C开头(第一页都是以C开头),或者以E开头,中间用引号括起一段文字. 以C开头的末尾输入两个数字a,b表示该页完后可以跳转到第a页或第b页, 以E开头的末尾输入一个单词,或者是HAPPY或者是GRISLY(有且仅有一页以HAPPY结尾). 现在要求你根据输入找出以第一页开头,以HAPPY结尾的路径,输出路径上每一页中间引号里面的内容,不包含引号. 思路:建立树,…
Apple Tree Description Wshxzt is a lovely girl. She likes apple very much. One day HX takes her to an apple tree. There are N nodes in the tree. Each node has an amount of apples. Wshxzt starts her happy trip at one node. She can eat up all the apple…
Contestants Division Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10704   Accepted: 3004 Description In the new ACM-ICPC Regional Contest, a special monitoring and submitting system will be set up, and students will be able to compete…
http://poj.org/problem?id=2425 典型的sg函数,建图搜sg函数预处理之后直接求每次游戏的异或和.仍然是因为看不懂题目卡了好久. 这道题大概有两个坑, 1.是搜索的时候vis数组应该在函数内声明(似乎这是我经常在搜索里犯的错误,为了省一点空间整道题都写错了): 2.是n个点的有向无环图边数上限是n^2(re了好久QAQ). 在漫长的查资料过程之后终于大概搞懂了sg函数的原理,愉快.下一篇大概会写一个小结. 代码 #include<cstdio> #include&l…
学习大佬:树的直径求法及证明 树的直径 定义: 一棵树的直径就是这棵树上存在的最长路径. 给定一棵树,树中每条边都有一个权值,树中两点之间的距离定义为连接两点的路径边权之和.树中最远的两个节点之间的距离被称为树的直径,连接这两点的路径被称为树的最长链.后者通常也可称为直径,即直径是一个数值概念,也可代指一条路径. 求法: 一.树形dp 时间复杂度:O( n ): 优点:代码量少实现方便. 不足:不容易记录路径. 实现过程: 状态:d[ x ] 以当前结点 x 为根的 子树的直径. 我们枚举每一个…