CodeForces 593D Happy Tree Party】的更多相关文章

题目链接: http://codeforces.com/problemset/problem/593/D --------------------------------------------------------------------------------------------------------------- 刚看完题目感觉必须用树链剖分之类的方法,就放弃了,然而我们要发现题目具有如下性质: 一个$ long long $以内的数如果被大于$1$的数除 几十次就可以除到$0$了…
题意:给一棵树,每条边有一个权值,给两种操作,第一种是询问y向下整除从a到b的最短路径中每条边的权值后y的值,第二种是改变某条边的权值. 思路:y的最大值为1e18,最多除大于等于2的数不超过60次即可将y变为0,先dfs以任意一点为根建树,记录每个点的深度和它的父结点并将边权转化为点权, 再搞个并查集,将权值为1的点压缩,即使pre[u]=g[u];(u变成u的爸爸). #include<bits/stdc++.h> #define fi first #define se second us…
Problem - D - Codeforces  Fix a Tree 看完第一名的代码,顿然醒悟... 我可以把所有单独的点全部当成线,那么只有线和环. 如果全是线的话,直接线的条数-1,便是操作数. 如果有环和线,环被打开的同时,接入到线上.那就是线和环的总数-1. 如果只有环的话,把所有的环打开,互相接入,共需n次操作. #include <cstdio> #include <algorithm> using namespace std; ; int cur[maxn];…
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard output Bogdan has a birthday today and mom gave him a tree consisting of n vertecies. For every edge of the tree i, some number xi was written on it. I…
Codeforces Round #329 (Div. 2) D. Happy Tree Party time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Bogdan has a birthday today and mom gave him a tree consisting of n vertecies. For every…
题目链接:http://codeforces.com/problemset/problem/765/E $DFS子$树进行$DP$ 大概分以下几种情况: 1.为叶子,直接返回. 2.长度不同的路径长度只有一条,显然可以合并成这一条的长度. 3.长度不同的路径长度有两条,并且这个点为根,显然可以合并成这两条的长度和. 4.其他的都不合法. 注意:事实上如果第一次$DP$之后不合法要考虑换根再做一次 #include<iostream> #include<cstdio> #includ…
链接:http://codeforces.com/problemset/problem/570/D D. Tree Requests time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Roman planted a tree consisting of n vertices. Each vertex contains a low…
Propagating tree Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Original ID: 383C64-bit integer IO format: %I64d      Java class name: (Any)   Iahub likes trees very much. Recently he discovered an interesting tr…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Roman planted a tree consisting of n vertices. Each vertex contains a lowercase English letter. Vertex 1 is the root of the tree, each of the n …
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连通图)且这颗树中必须包含节点1 然后将这颗子树中的所有点的点权+1或-1 求把所有点权全部变为0的最小次数(n<=10^5) 题解: 因为每一次的子树中都必须有1,所以我们得知每一次变换的话1的权值都会变化 所以我们以1为根 现在,我们发现,如果一个节点的权值发生变化,那么他的父节点的权值一定发生变…