https://codeforces.com/contest/1062/problem/E 题意 给一颗树n,然后q个询问,询问编号l~r的点,假设可以删除一个点,使得他们的最近公共祖先深度最大.每次询问,输出删除的点和祖先的深度 思路 考虑dfs序来判断v是否在u的子树里: dfn[u]<dfn[v]<=max(dfn[u的子树]) 那么进一步拓展,dfs序之差越大,点就在越分离的地方,这些点的lca一定是lca(max(dfn[u]),min(dfn[u])) 这不仅知道了需要去掉哪个点(…
Codeforces Round #520 (Div. 2) https://codeforces.com/contest/1062 A #include<bits/stdc++.h> using namespace std; #define lson l,mid,rt<<1 #define rson mid+1,r,rt<<1|1 #define sqr(x) ((x)*(x)) #define pb push_back #define eb emplace_back…
A. A Prank Solved. 题意: 给出一串数字,每个数字的范围是$[1, 1000]$,并且这个序列是递增的,求最多擦除掉多少个数字,使得别人一看就知道缺的数字是什么. 思路: 显然,如果缺的这块数字的个数刚好等于右界 - 左界 + 1 那么就可以知道 还需要考虑数据范围,因为是$<= 1000  和 >= 1$ 那么对于两边的边界需要特殊考虑. #include <bits/stdc++.h> using namespace std; #define N 110 in…
D. MADMAX time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output As we all know, Max is the best video game player among her friends. Her friends were so jealous of hers, that they created an actu…
A. Maze 题目连接: http://codeforces.com/contest/377/problem/A Description Pavel loves grid mazes. A grid maze is an n × m rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and h…
C. Xor-tree Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/430/problem/C Description Iahub is very proud of his recent discovery, propagating trees. Right now, he invented a new tree, called xor-tree. After this new revolu…
题目链接:http://codeforces.com/contest/767/problem/C 题解:类似于提着一串葡萄,用剪刀剪两条藤,葡萄分成了三串.问怎样剪才能使三串葡萄的质量相等. 首先要做的就是统计葡萄的总质量tot.之后就是找到两子串质量为(tot/3)的葡萄(如果除不尽,则必定找不到),那么剩下的就是dfs搜索了. 我一开始的做法是先建一棵记录子树质量和的树,然后再从上往下dfs,如果找到了,就把它剪掉.后来发现被剪掉的那一串可能就含有两串质量为(tot/3)的葡萄(这里质量 可…
题意:给出一棵树,共有n个节点,其中根节点是Kefa的家,叶子是restaurant,a[i]....a[n]表示i节点是否有猫,问:Kefa要去restaurant并且不能连续经过m个有猫的节点有多少条路径: 思路:先用vector数组建树: 再dfs..(第一次用vector建树,还看了别人的代码,果然是zz): 代码: #include <bits/stdc++.h> #define ll long long #define MAXN 100000+10 using namespace…
D. Fedor and Essay time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output After you had helped Fedor to find friends in the «Call of Soldiers 3» game, he stopped studying completely. Today, the E…
#include<bits/stdc++.h>using namespace std;const int N=200005;int n,A[N];long long Mx,tot,S[N];vector<int>Adj[N];void DFS(int v,int p){    S[v]=A[v];    for(int &u:Adj[v])        if(u!=p)            DFS(u,v),S[v]+=S[u];    if(p)//0号结点是不存在的…