Codeforces 1304E. 1-Trees and Queries】的更多相关文章

Home » Practice(Hard) » Dynamic Trees and Queries Problem Code: ANUDTQSubmit https://www.codechef.com/problems/ANUDTQ Tweet   All submissions for this problem are available. Read problems statements in Mandarin Chineseand Russian. Given a directed tr…
https://codeforces.com/contest/1304/problem/E #include<bits/stdc++.h> using namespace std; typedef long long ll; ; ; vector<int> G[maxn]; int depth[maxn]; int fa[maxn][maxbit]; int Log[maxn]; int N; void pre(){ Log[] = -; Log[] = ,Log[] = ; ;i…
题意 给你一棵树,q个询问(x,y,a,b,k),每次问你如果在(x,y)加一条边,那么a到b能不能走k步,同一个点可以走多次 思路(翻译题解) 对于一条a到b的最短路径x,可以通过左右横跳的方法把他扩大成任意的\(x+2i(i\geq 0)\),只要存在一个能使得它等于k的i即可.. 在这一题中,如果x和i连了边,那么就会存在三条可能的最短路径:(从哪到哪都是在原树上) 1.从a到b 2.从a到x,走加的边到y,从y到b 3.从a到y,走加的边到x,从x到b 判断是否存在满足就好了 代码 思路…
简述题意,给你一课最小支撑树,对每个询问,在原有的路径上增加x-y,问a-b是否有路径长度为k的路,每条路每个点可以重复使用 由于是最小支撑树,我们可以用LCA来快速判断每个点之间的距离,那么现在就要判断情况,假设从原有的路上,a-b的距离为d,d=k时显然成立,当d<k时,若(d-k)%2=0也成立,因为若其是2的倍数,他可以轮流进入b与b的前驱,最后停在b上,那么我们如何判断新加的边的,距离的判定和前者一样,但是距离的大小变化了,设(x,y)表示x到y的最短路径,则从a到b就有三种情况 1.…
C. Coloring Trees time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output ZS the Coder and Chris the Baboon has arrived at Udayland! They walked in the park where n trees grow. They decided to be…
题目链接: A. Sonya and Queries time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty…
Description You have a rooted tree consisting of n vertices. Each vertex of the tree has some color. We will assume that the tree vertices are numbered by integers from 1 to n. Then we represent the color of vertex v as cv. The tree root is a vertex…
题目链接:http://codeforces.com/problemset/problem/711/C O(n^4)的复杂度,以为会超时的 思路:dp[i][j][k]表示第i棵数用颜色k涂完后beauty为j #include<bits/stdc++.h> using namespace std; typedef long long ll; const ll inf=1e15; int c[105]; int p[105][105]; ll dp[105][105][105]; int ma…
题目链接: http://codeforces.com/problemset/problem/711/C 题目大意: 给N棵树,M种颜色,已经有颜色的不能涂色,没颜色为0,可以涂色,每棵树I涂成颜色J花费PIJ.求分成K个颜色段(1112221为3个颜色段)的最小花费.无解输出-1. 题目思路: [动态规划] f[i][j][k]表示前i个树分成j段,最后一个颜色是k的花费. 根据当前这棵树是否可以涂色,上一棵树是否可以涂色转移. 直接枚举这个树和上棵树的颜色,N4居然没T. // //by c…
Description You are given an array a of size n, and q queries to it. There are queries of two types: 1 li ri — perform a cyclic shift of the segment [li, ri] to the right. That is, for every x such that li ≤ x < ri new value of ax + 1 becomes equal t…