Shorten Diameter Time limit : 2sec / Stack limit : 256MB / Memory limit : 256MB Score : 600 points Problem Statement Given an undirected tree, let the distance between vertices u and v be the number of edges on the simple path from u to v. The diamet…
链接:http://agc001.contest.atcoder.jp/tasks/agc001_c 题解(官方): We use the following well-known fact about trees.Let T be a tree, and let D be the diameter of the tree. • If D is even, there exists an vertex v of T such that for each vertex w inT, the dis…
题目: Problem Statement Given an undirected tree, let the distance between vertices \(u\) and \(v\) be the number of edges on the simple path from \(u\) to \(v\). The diameter of a tree is the maximum among the distances between any two vertices. We wi…
一开始没看到要保证最后是树--所以一定要从叶子开始删 枚举重心,如果k是偶数,那么按当前重心提起来deep大于k/2的全都要切掉,这样枚举重心然后取min即可 奇数的话就是枚举直径中间的边,然后从两边的点分别dfs删点 #include<iostream> #include<cstdio> using namespace std; const int N=5005; int n,k,m,h[N],cnt,ans=1e9,sm; struct qwe { int ne,no,to;…
AGC001 A - BBQ Easy 从第\(2n - 1\)个隔一个加一下加到1即可 #include <bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define mp make_pair #define pb push_back #define space putchar(' ') #define enter putchar('\n') #define eps 1e-…