网上的大多是用树的直径做的,但是一些比较巧妙的做法,来自https://www.cnblogs.com/qldabiaoge/p/9315722.html. 首先用set数组维护每一个节点所连接的边的信息,然后遍历一遍所有的点,把度为1的点放入集合s,(把距离作为第一要素): 然后把集合s中的点从小到大枚举,每个点存储的信息是该点及其该点的子节点中到该点的父亲节点的最大距离: 枚举一个点后,把它从集合s和它父亲节点中删除.如果这个时候父节点的度变成1了,说明这个节点是父亲节点到所有子节点中距离的…
E. Sonya and Ice Cream time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Sonya likes ice cream very much. She eats it even during programming competitions. That is why the girl decided that…
A. Free Ice Cream 题目连接: http://www.codeforces.com/contest/686/problem/A Description After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer. At the start of the day they hav…
题目链接 set维护最小值贪心, 刚开始用树的直径+单调队列没调出来... #include <iostream>#include <cstdio> #include <set> #define REP(i,a,n) for(int i=a;i<=n;++i) #define x first #define y second using namespace std; typedef pair<int,int> pii; , INF = 0x3f3f3f…
题面在这里! 挺智障的一个二分...我还写了好久QWQ,退役算啦 题解见注释... /* 先对每个点记录 向子树外的最长路 和 向子树内最长路,然后二分. 二分的时候枚举链的LCA直接做就好啦. */ #include<bits/stdc++.h> #define ll long long using namespace std; #define pb push_back const int N=100005,B=2333333; inline int read(){ int x=0; cha…
题目描述 给定一个 \(N\) 个点的树,要选出一条所含点的个数不超过 \(K\) 的一条路径,使得路径外的点到这条路径的距离的最大值最小. 数据范围:\(1\le K \le N \le 10^5\) 解题思路 这道题我有两种方法. 方法一 我们考虑一个性质:选出来的链一定会是直径的一部分. 不然就肯定会存在可能更新最大值的一个分支,而且这个分支的大小一定会不比路径包含在直径上时小. 同样的道理,我们发现这条路径在直径上越长越好. 那么我们不妨先把直径抠出来,记作一个序列,那么这颗树就可以想象…
Problem   Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Description Input Output Print exactly one integer — the beauty of the product of the strings. Sample Input 3aba Sample Output 3 题解:这个题的思维难度其实不大,需要维护什么东西很容易想到,或…
Problem   Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Input The first line contains a single integer nn (2≤n≤150000) — the number of kittens. Each of the following n−1lines contains integers xi and yi (1≤xi,…
Problem   Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input Output The first line of output should contain "Yes", if it's possible to do a correct evaluation for all the dishes, or "No" otherwis…
Problem   Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input The first and only line contains a single integer mm (1≤m≤100000,1≤m≤100000). Output Print a single integer — the expected length of the array aa writte…