codeforces GYM 100781A【树的直径】】的更多相关文章

先求出每棵树的直径,排个序,要想图的直径最小的话需要每棵树的直径中点像直径最大的树的直径中点连边,这样直径有三种情况:是直径最大的树的直径:a[tot]:是直径最大的树和直径第二大的树的半径拼起来+1:(a[tot]+1)/2+(a[tot-1]+1)/2+1):是直径第二大的树和直径第三大的树的半径拼起来+2:(a[tot-1]+1)/2+(a[tot-2]+1)/2+2 取max即可 #include<iostream> #include<cstdio> #include<…
题目链接: http://codeforces.com/gym/100114 Description The computer network of “Plunder & Flee Inc.” consists of n servers and m two-way communication links. Two servers can communicate either through a direct link, or through a chain of links, by relayi…
J. Computer Network Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Description The computer network of “Plunder & Flee Inc.” consists of n servers and m two-way communication links. Two servers can communicate either thr…
题意: n个点,m条边,m <= n <= 100000,边的长度都为1. 点从 0 ~ n-1 编号.开始时图是不连通的,并且没有环. 通过加入一些边后,可以使图连通.要求加入的边不能多余(即生成的图是一棵树). 问连通后的图,任意两点之间的距离的最大值,最小可以是多少? 既然刚开始图不连通也无环,那么就是一些树(特殊情况是点). 于是题目就变成了,如何把很多棵树连起来,使最后生成的树直径最小. 可以想到,如果把两棵直径为 a 和 b 的树加一条边连成一棵,那么直径最小的新树直径为 (a+1…
Time limit 2000 ms Memory limit 262144 kB Source Codeforces Round #328 (Div. 2) Ari the monster is not an ordinary monster. She is the hidden identity of Super M, the Byteforces’ superhero. Byteforces is a country that consists of n cities, connected…
题目链接: http://codeforces.com/contest/14/problem/D D. Two Paths time limit per test2 secondsmemory limit per test64 megabytes 问题描述 As you know, Bob's brother lives in Flatland. In Flatland there are n cities, connected by n - 1 two-way roads. The citie…
题目链接:http://codeforces.com/problemset/problem/455/C 题意: 给你一个森林,n个点,m条边. 然后有t个操作.共有两种操作: (1)1 x: 输出节点x所在树的直径. (2)2 x y: 如果x,y不在同一棵树上的话,用一条边连接x,y所在的树,并且使得到的新树的直径尽可能小. 题解: 首先对于初始状态,算出每一棵树的直径d[find(i)]. 每次合并树的时候,因为要尽可能让新树直径变小,所以显然这条边要分别连接两棵树直径的“中点”. 所以新树…
题目链接:http://codeforces.com/problemset/problem/337/D 题意: 给你一棵树,n个节点. 如果一个节点处放着“罪恶之书”,那么它会影响周围距离不超过d的所有节点. 然后告诉你一部分被影响的节点aff[i],共m个. 已知有且仅有一个节点放着“罪恶之书”. 现在问你有多少个节点可能放着“罪恶之书”. 题解: 如果一个节点放着“罪恶之书”,那么它到所有aff[i]的距离都不超过d. 也就是:max(它到aff[i]的距离) <= d 有一个关于树的直径的…
Ari the monster is not an ordinary monster. She is the hidden identity of Super M, the Byteforces’ superhero. Byteforces is a country that consists of n cities, connected by n - 1 bidirectional roads. Every road connects exactly two distinct cities,…
E - We Need More Bosses CodeForces - 1000E Your friend is developing a computer game. He has already decided how the game world should look like - it should consist of nn locations connected by mm two-waypassages. The passages are designed in such a…