Codeforces 1129 E.Legendary Tree】的更多相关文章

Codeforces 1129 E.Legendary Tree 解题思路: 这题好厉害,我来复读一下官方题解,顺便补充几句. 首先,可以通过询问 \(n-1​\) 次 \((S=\{1\},T=\{2\dots n\},i),i\in[2,n]​\) ,来得到以 \(1​\) 为根树的所有节点的子树大小. 然后考虑从子树大小最小的节点开始,为每一个节点找它们的儿子,由于每个节点儿子的子树大小,一定小于这个节点的子树大小,所以可以按照子树大小从小到大排序,每个节点的儿子就一定在其前面. 假设已经…
题目链接:Codeforces 461B Appleman and Tree 题目大意:一棵树,以0节点为根节点,给定每一个节点的父亲节点,以及每一个点的颜色(0表示白色,1表示黑色),切断这棵树的k条边,使得树变成k+1个联通分量.保证每一个联通分量有且仅有1个黑色节点.问有多少种切割方法. 解题思路:树形dp,dp[i][0]和dp[i][1]分别表示子树一下的切割方法中,i节点所在联通块不存在黑节点和已经存在一个黑节点的方案数. #include <cstdio> #include &l…
Codeforces 1129 D. Isolation 解题思路: 令 \(f(l,r)\) 为 \([l,r]\) 中之出现一次的元素个数,然后可以得到暴力 \(\text{dp}\) 的式子. \[ dp[i]=\sum_{j=i-1}[f(j+1,i)\leq k]dp[j] \] 实际上任意一个位置为左端点,\(i\) 为右端点的 \(f(l,r)\) 值是可以动态维护的. \((i-1)\rightarrow i\) ,设 \(pre[i]\) 为 \(i\) 之前上一个出现 \(a…
Codeforces 280C Game on tree LINK 题目大意:给你一棵树,1号节点是根,每次等概率选择没有被染黑的一个节点染黑其所有子树中的节点,问染黑所有节点的期望次数 #include<bits/stdc++.h> using namespace std; #define N 100010 int n,tot=0,head[N]={0}; struct Edge{int v,nxt;}E[N<<1]; void add(int u,int v){ E[++tot…
题目描述: Game on Tree time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Momiji has got a rooted tree, consisting of n nodes. The tree nodes are numbered by integers from 1 to n. The root has num…
Codeforces Round #781 C. Tree Infection time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output A tree is a connected graph without cycles. A rooted tree has a special vertex called the root. The p…
Codeforces 题面传送门 & 洛谷题面传送门 考虑以 \(1\) 为根,记 \(siz_i\) 为 \(i\) 子树的大小,那么可以通过询问 \(S=\{2,3,\cdots,n\},T=\{1\}\) 以及每个 \(u\) 得出 \(siz_u\) 的值. 考虑将所有点按 \(siz\) 从小到大排序并维护一个集合 \(st\) 表示目前还没有找到父亲的点的集合,那么我们枚举到一个点 \(x\) 时就在 \(st\) 中二分找到所有父亲为 \(x\) 的点并将它们从 \(st\) 中删…
题目链接 \(Description\) 有一棵\(n\)个点的树.你需要在\(11111\)次询问内确定出这棵树的形态.每次询问你给定两个非空且不相交的点集\(S,T\)和一个点\(u\),交互库会告诉你满足\(x\in S,y\in T\),且\(x\to y\)经过了\(u\)的点对\((x,y)\)的数量. \(n\leq500\). \(Solution\) 不妨假设以\(1\)为根.首先如果想知道\(y\)是否在\(x\)的子树内,询问\(S=\{1\},T=\{y\},u=x\)就…
E. Anton and Tree time limit per test: 3 seconds memory limit per test :256 megabytes input:standard input output: standard output Anton is growing a tree in his garden. In case you forgot, the tree is a connected acyclic undirected graph. There are …
题目链接: 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…