题意:无向联通图,求一条最长的路径,路径长度定义为u到v必须经过的边的个数 如果把强联通分量都缩成一个点以后,每个点内部的边都是可替代的:而又因为这是个无向图,缩完点以后就是棵树,跑两遍dfs求直径即可 #include<bits/stdc++.h> #define pa pair<int,int> #define CLR(a,x) memset(a,x,sizeof(a)) using namespace std; typedef long long ll; ; inline l…
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…
题目链接: 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…
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-way passages. The passages are designed in such a way that it should be possible to get from…
题目链接: Anton and Tree 题意:给出一棵树由0和1构成,一次操作可以将树上一块相同的数字转换为另一个(0->1 , 1->0),求最少几次操作可以把这棵数转化为只有一个数字的一棵数. 题解:首先一次可以改变一片数字,那么进行缩点后就变成了每次改变一个点.缩完点后这棵数变成了一棵相邻节点不同,0和1相交叉的一棵树.然后一棵树的直径上就是 这种情况,相当于从中间开始操作,总共操作(L+1)/2次.关于其他的分支一定会在直径的改变过程中完成改变. #include<bits/s…