Codeforces 429 A. Xor-tree】的更多相关文章

题目链接: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 E.Legendary Tree 解题思路: 这题好厉害,我来复读一下官方题解,顺便补充几句. 首先,可以通过询问 \(n-1​\) 次 \((S=\{1\},T=\{2\dots n\},i),i\in[2,n]​\) ,来得到以 \(1​\) 为根树的所有节点的子树大小. 然后考虑从子树大小最小的节点开始,为每一个节点找它们的儿子,由于每个节点儿子的子树大小,一定小于这个节点的子树大小,所以可以按照子树大小从小到大排序,每个节点的儿子就一定在其前面. 假设已经…
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…
B. Working out time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the beach. The gym where the…
题目描述: 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…
[多校联考2019(Round 5)] [ATCoder3912]Xor Tree(状压dp) 题面 给出一棵n个点的树,每条边有边权v,每次操作选中两个点,将这两个点之间的路径上的边权全部异或某个值,求使得最终所有边权为0的最小操作次数. \(v \leq 15,n \leq 10^5\) 分析 首先把边权转化为点权.记一个点的点权为与它相连的所有边的边权和.当我们给一条路径上的边异或上某个值时,路径端点的点权被异或了1次,而路径上不是端点的点有两条边被异或了,相当于异或了2次,权值不变.因此…
「AGC035C」 Skolem XOR Tree 感觉有那么一点点上道了? 首先对于一个 \(n\),若 \(n\equiv 3 \pmod 4\),我们很快能够构造出一个合法解如 \(n,n-1,n-2,..,1,n+n,n+n-1,n+n-2,...,n+1\). 若 \(n\equiv 1 \pmod 4\),我们将 \(n,n-1\) 拆分出来单独成一条链. 然后如果 \(n\) 是偶数,可以想到对于这个 \(n\) 单独处理,则剩下的问题转化为我们上面的问题. 考虑对于这个偶数特殊判…
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…
http://codeforces.com/problemset/problem/242/E 题意:给出初始n个数,还有m个操作,操作一种是区间求和,一种是区间xor x. 思路:昨天比赛出的一道类似题目,对于一个数,把它变成二进制,那么做xor操作的时候,其实如果那一位xor 1,那么就是取反,否则不变.于是,可以对每一个二进制位开一棵线段树,由于数字最大有1e6,所以只需要开log(1e6) = 20棵线段树.对每一棵线段树统计区间内1的个数,那一位对答案的贡献就是那一位的权值*区间1的个数…
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 …