CF455C Civilization】的更多相关文章

CF456E Codeforces Round #260 (Div. 1) C Codeforces Round #260 (Div. 2) E http://codeforces.com/contest/455/problem/C C. Civilization time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Andrew p…
并查集维护每个联通块的直径和最小的最大深度,每次连得时候连的肯定是最大深度最小的那两个点 #pragma GCC optimize(3) #include<bits/stdc++.h> #define pa pair<ll,ll> #define CLR(a,x) memset(a,x,sizeof(a)) using namespace std; typedef long long ll; ; inline char gc(){ return getchar(); <<…
题目链接: https://www.luogu.org/problemnew/show/P2195 http://codeforces.com/contest/455/problem/C 显然我们可以想到要用并查集来维护联通节点的信息. 然后题目要求的是合并之后树的直径最小. 然后我们可以知道在两个树的中点合并是最好的.所以我们设\(len[i]\)为i所在树的直径,那么按照上述策略,合并\(i,j\)之后新树的直径就是\(max(len[i],len[j],(len[i]+1)/2+(len[…
问题描述 LG-CF455C 题解 首先,题目给出了 \(m\) 条边,对这 \(n\) 个点, \(m\) 条边组成的森林,跑出每棵树的直径,同时使用并查集维护树的连通性. 考虑合并两棵树的情况:设这两棵树的代表元为 \(u,v\) ,这棵树的直径有三种来源: \(u\) 这棵树的直径 \(v\) 这棵树的直径 穿过 \(u,v\) 合并边的一条路径 \(u,v\) 两棵树的直径是已知的,所以我们只需要考虑最小化第三种情况. 设树 \(u,v\) 合并时的点为 \(rt_u,rt_v\) ,此…
嘟嘟嘟 水题一道,某谷又恶意评分. 合并无非是将两棵树的直径的中点连一块,记原来两棵树的直径为\(d_1, d_2\),那么新的树的直径就是\(max(d_1, d_2, \lceil \frac{d_1}{2} \rceil + \lceil \frac{d_2}{2} \rceil + 1)\),用并查集合并,更新即可. #include<cstdio> #include<iostream> #include<cmath> #include<algorithm…
因为本蒻实在太蒻了...对于即将到来的NOIP2018ssfd,所以下决心要把自己近期做过的题目(衡量标准为洛谷蓝题难度或以上)整理一下,归归类,简单地写一下思路,就当作自己复习了吧qwq 本随笔持续更新,自2018.9.19开始,计划更新到2018NOIP截止 (但是因为最近写的比赛题比较多..但是没有办法把这些题放上来..所以只能放上主流OJ上面有的题) 如果本蒻今年有幸没有AFO掉,flag先里在这里--之后学省选知识点的时候会重开一贴更新的,到时候希望是更有难度的题目吧. 搜索 [NOI…
搜索 [NOIP2013]华容道 最短路+带剪枝的搜索,是一个思维难度比较大的题目. CF1064D Labyrinth 考虑贪心,用双向队列bfs [NOIP2017]宝藏 剪枝搜索出奇迹 题解:https://www.cnblogs.com/fengxunling/p/9777606.html luogu 有趣的数 [ZJOI2007] 时态同步 [NOIP2002] 矩形覆盖 这题数据太水... 题解:https://www.cnblogs.com/fengxunling/p/984161…
C. Civilization Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/455/problem/C Description Andrew plays a game called "Civilization". Dima helps him. The game has n cities and m bidirectional roads. The cities are numbe…
Civilization 题目链接: http://acm.hust.edu.cn/vjudge/contest/121334#problem/B Description Andrew plays a game called "Civilization". Dima helps him. The game has n cities and m bidirectional roads. The cities are numbered from 1 to n. Between any pa…
题目链接: 题目 C. Civilization time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output 问题描述 Andrew plays a game called "Civilization". Dima helps him. The game has n cities and m bidirectional roads. Th…