题目大意: 给两个树,求环的个数. 题目分析: 出题人摆错题号系列. 通过画图很容易就能想到把新图拆在两个树上,在树上游走成环. 考虑DP状态F,G,T.F表示最终答案,T表示儿子不考虑父亲,G表示父亲不考虑儿子.T通过从下往上做NTT,G通过从上往下做NTT.F顺便做NTT. 最后做一下拼接就行. 代码: #include<bits/stdc++.h> using namespace std; ; ; ; ],k; vector <][maxn]; ][maxn][],gi[][max…
题意: There is a city which is built like a tree.A terrorist wants to destroy the city's roads. But now he is alone, he can only destroy one road, then the city will be divided into two cities. Impression of the city is a number defined as the distance…
题目链接: http://codeforces.com/contest/161/problem/D D. Distance in Tree time limit per test 3 secondsmemory limit per test 512 megabytes 问题描述 A tree is a connected graph that doesn't contain any cycles. The distance between two vertices of a tree is th…
C - 树形dp Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Description After Farmer John realized that Bessie had installed a "tree-shaped" network among his N (…
分析: 听说正解是FFT+线段树合并,然而我并不会... 我们来思考其他的方法. 我们要求的是连通块第k大的和 对于某一个连通块,对答案的贡献=val(Rank.K) 我们不好直接算出每个连通块的Rank.K是多少 但我们可以枚举一个limit for 1->w ,Σ(val(Rank.K)>=lim的连通块的个数)就等于答案 为什么呢,因为这样一个连通块就被统计了val(Rank.K)次. 剩下的进行树形DP,设dp[i][j]为以i为根的子树,选出j个权值>=limit的点的方案数.…
D. Two Paths 题目连接: http://codeforces.com/contest/14/problem/D Description As you know, Bob's brother lives in Flatland. In Flatland there are n cities, connected by n - 1 two-way roads. The cities are numbered from 1 to n. You can get from one city t…
Two Paths time limit per test 2 seconds memory limit per test 64 megabytes input standard input output standard output As you know, Bob's brother lives in Flatland. In Flatland there are n cities, connected by n - 1 two-way roads. The cities are numb…
学习大佬:树的直径求法及证明 树的直径 定义: 一棵树的直径就是这棵树上存在的最长路径. 给定一棵树,树中每条边都有一个权值,树中两点之间的距离定义为连接两点的路径边权之和.树中最远的两个节点之间的距离被称为树的直径,连接这两点的路径被称为树的最长链.后者通常也可称为直径,即直径是一个数值概念,也可代指一条路径. 求法: 一.树形dp 时间复杂度:O( n ): 优点:代码量少实现方便. 不足:不容易记录路径. 实现过程: 状态:d[ x ] 以当前结点 x 为根的 子树的直径. 我们枚举每一个…
LINK:网络收费 还是自己没脑子. 早上思考的时候 发现树形dp不可做 然后放弃治疗了. 没有合理的转换问题的模型是我整个人最大的败笔. 暴力也值得一提 爆搜之后可以写成FFT的形式的计算贡献的方法 连图都不用建出来. 不是传统的树形dp 因为子树的状态影响之后的决策 并且从下至上的话需要状压所有点的状态 从上之下的话代价难以统计. 观察图中的这张表格 容易发现有规律的事情 当 na<nb时 有A的一定付出代价 两个A的话就两倍 一个A的话就一倍 B的话不要代价. 容易转换成上述模型 于是 这…
Network Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4478   Accepted: 1292 Description Yixght is a manager of the company called SzqNetwork(SN). Now she's very worried because she has just received a bad news which denotes that DxtNet…