Solutions are presented as using the least memory and the fastest execution time. It also takes the top
10 most recent solutions from each language. If you want to limit to a specific index, click the
"Solved" button and go to that problem.
Problems
Pasha is a good student and one of MoJaK's best friends. He always have a problem to think about. Today they had a talk about the following problem. We have a forest (acyclic undirected graph) with n vertices and m edges. There are q queries we should answer. In each query two vertices v and u are given. Let V be the set of vertices in the connected component of the graph that contains v , and U be the set of vertices in the connected component of the graph that contains u . Let's add an edge between some vertex and some vertex in and compute the value d of the resulting component. If the resulting component is a tree, the value d is the diameter of the component, and it is equal to -1 otherwise. What is the expected value of d , if we choose vertices a and b from the sets uniformly at random? Can you help Pasha to solve this problem? The diameter of the component is the maximum distance among some pair of vertices in the component. The distance between two vertices is the minimum number of edges on some path between the two vertices. Note that queries don't add edges to the initial forest. The first line contains three integers n , m and q ( 1 ≤ n , m , q ≤ 10 5 ) — the number of vertices, the number of edges in the graph and the number of queries. Each of the next m lines contains two integers u i and v i ( 1 ≤ u i , v i ≤ n ), that means there is an edge between vertices u i and v i . It is guaranteed that the given graph is a forest. Each of the next q lines contains two integers u i and v i ( 1 ≤ u i , v i ≤ n ) — the vertices given in the i -th query. For each query print the expected value of d as described in the problem statement. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6 . Let's assume that your answer is a , and the jury's answer is b . The checker program will consider your answer correct, if . In the first example the vertices 1 and 3 are in the same component, so the answer for the first q |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
|
26920098 |
FalseMirror |
D |
May 7, 2017, 9:18 a.m. |
OK |
D |
TESTS |
102 |
717 |
36454400 |
|
2600 |
|
26920142 |
FalseMirror |
D |
May 7, 2017, 9:21 a.m. |
OK |
D |
TESTS |
102 |
997 |
36454400 |
|
2600 |
|
26920130 |
FalseMirror |
D |
May 7, 2017, 9:20 a.m. |
OK |
D |
TESTS |
102 |
1076 |
36454400 |
|
2600 |
|
26920192 |
FalseMirror |
D |
May 7, 2017, 9:23 a.m. |
OK |
D |
TESTS |
102 |
1294 |
38195200 |
|
2600 |
|
41006278 |
Scut82 |
D |
July 31, 2018, 9:53 a.m. |
OK |
GNU C++ |
TESTS |
102 |
156 |
13209600 |
|
2600 |
|
26899536 |
unicornt |
D |
May 6, 2017, 11:08 a.m. |
OK |
GNU C++ |
TESTS |
102 |
171 |
14438400 |
|
2600 |
|
26873994 |
Chloe_fan |
D |
May 5, 2017, 6:12 a.m. |
OK |
GNU C++ |
TESTS |
102 |
171 |
17100800 |
|
2600 |
|
26877802 |
1919810 |
D |
May 5, 2017, 10:07 a.m. |
OK |
GNU C++ |
TESTS |
102 |
187 |
18022400 |
|
2600 |
|
40980964 |
ReaLNero1 |
D |
July 30, 2018, 5:46 p.m. |
OK |
GNU C++ |
TESTS |
102 |
187 |
26316800 |
|
2600 |
|
26972793 |
unicornt |
D |
May 9, 2017, 11:41 a.m. |
OK |
GNU C++ |
TESTS |
102 |
202 |
14438400 |
|
2600 |
|
26971323 |
chihiro |
D |
May 9, 2017, 9:52 a.m. |
OK |
GNU C++ |
TESTS |
102 |
202 |
17612800 |
|
2600 |
|
36987328 |
alan_cty |
D |
April 5, 2018, 4:09 a.m. |
OK |
GNU C++ |
TESTS |
102 |
217 |
16998400 |
|
2600 |
|
32002738 |
diaosipan |
D |
Nov. 3, 2017, 9:15 a.m. |
OK |
GNU C++ |
TESTS |
102 |
218 |
16793600 |
|
2600 |
|
40981531 |
ReaLNero1 |
D |
July 30, 2018, 6:02 p.m. |
OK |
GNU C++ |
TESTS |
102 |
218 |
17100800 |
|
2600 |
|
32444975 |
hesihesiwujiuwu |
D |
Nov. 19, 2017, 1:10 a.m. |
OK |
GNU C++11 |
TESTS |
102 |
171 |
22118400 |
|
2600 |
|
27210278 |
rqgao2014 |
D |
May 19, 2017, 8:09 a.m. |
OK |
GNU C++11 |
TESTS |
102 |
202 |
20377600 |
|
2600 |
|
26859812 |
423555290 |
D |
May 4, 2017, 4:27 p.m. |
OK |
GNU C++11 |
TESTS |
102 |
218 |
9830400 |
|
2600 |
|
26900477 |
LIN452 |
D |
May 6, 2017, 11:59 a.m. |
OK |
GNU C++11 |
TESTS |
102 |
218 |
11264000 |
|
2600 |
|
59572143 |
zx2003 |
D |
Aug. 27, 2019, 12:57 p.m. |
OK |
GNU C++11 |
TESTS |
102 |
218 |
20480000 |
|
2600 |
|
55414728 |
xgcjay |
D |
June 11, 2019, 12:39 a.m. |
OK |
GNU C++11 |
TESTS |
102 |
218 |
30208000 |
|
2600 |
|
26961788 |
PlayfulPanda |
D |
May 8, 2017, 5:43 p.m. |
OK |
GNU C++11 |
TESTS |
102 |
233 |
12800000 |
|
2600 |
|
62400294 |
AutumnKite |
D |
Oct. 12, 2019, 7:08 a.m. |
OK |
GNU C++11 |
TESTS |
102 |
233 |
13619200 |
|
2600 |
|
43900638 |
emoairx |
D |
Oct. 6, 2018, 12:23 p.m. |
OK |
GNU C++11 |
TESTS |
102 |
233 |
14438400 |
|
2600 |
|
62399328 |
wyy2004 |
D |
Oct. 12, 2019, 6:47 a.m. |
OK |
GNU C++11 |
TESTS |
102 |
233 |
15974400 |
|
2600 |
|
26858655 |
KADR |
D |
May 4, 2017, 4:18 p.m. |
OK |
GNU C++14 |
TESTS |
102 |
218 |
16793600 |
|
2600 |
|
28751618 |
jiaqiyang |
D |
July 21, 2017, 1:56 p.m. |
OK |
GNU C++14 |
TESTS |
102 |
264 |
13721600 |
|
2600 |
|
26885714 |
zhymaoiing |
D |
May 5, 2017, 5:05 p.m. |
OK |
GNU C++14 |
TESTS |
102 |
265 |
11161600 |
|
2600 |
|
32518562 |
RiKang |
D |
Nov. 21, 2017, 7:32 a.m. |
OK |
GNU C++14 |
TESTS |
102 |
265 |
12902400 |
|
2600 |
|
32087335 |
King_George |
D |
Nov. 6, 2017, 4:36 a.m. |
OK |
GNU C++14 |
TESTS |
102 |
265 |
17203200 |
|
2600 |
|
26900277 |
JoeyWheeler |
D |
May 6, 2017, 11:47 a.m. |
OK |
GNU C++14 |
TESTS |
102 |
280 |
13721600 |
|
2600 |
|
26899987 |
Hujiwara |
D |
May 6, 2017, 11:31 a.m. |
OK |
GNU C++14 |
TESTS |
102 |
280 |
18739200 |
|
2600 |
|
31632119 |
woqja125 |
D |
Oct. 23, 2017, 2:20 p.m. |
OK |
GNU C++14 |
TESTS |
102 |
280 |
22732800 |
|
2600 |
|
27729629 |
pps789 |
D |
June 12, 2017, 2:19 a.m. |
OK |
GNU C++14 |
TESTS |
102 |
295 |
19148800 |
|
2600 |
|
26881318 |
YaKon4ick |
D |
May 5, 2017, 1:14 p.m. |
OK |
GNU C++14 |
TESTS |
102 |
295 |
19353600 |
|
2600 |
|
64507917 |
xxyu |
D |
Nov. 8, 2019, 7:41 a.m. |
OK |
GNU C++17 |
TESTS |
102 |
265 |
26419200 |
|
2600 |
|
64507783 |
xxyu |
D |
Nov. 8, 2019, 7:37 a.m. |
OK |
GNU C++17 |
TESTS |
102 |
280 |
26419200 |
|
2600 |
|
68025785 |
YaoBIG |
D |
Jan. 1, 2020, 5:35 a.m. |
OK |
GNU C++17 |
TESTS |
102 |
296 |
16076800 |
|
2600 |
|
65816334 |
ivan100sic |
D |
Nov. 27, 2019, 9:35 a.m. |
OK |
GNU C++17 |
TESTS |
102 |
327 |
20070400 |
|
2600 |
|
54883055 |
hjk1030 |
D |
May 31, 2019, 3:30 p.m. |
OK |
GNU C++17 |
TESTS |
102 |
343 |
24678400 |
|
2600 |
|
61925547 |
yan.silva |
D |
Oct. 5, 2019, 2:31 p.m. |
OK |
GNU C++17 |
TESTS |
102 |
373 |
16384000 |
|
2600 |
|
55866700 |
vjudge5 |
D |
June 21, 2019, 12:32 p.m. |
OK |
GNU C++17 |
TESTS |
102 |
374 |
19046400 |
|
2600 |
|
55866704 |
E869120 |
D |
June 21, 2019, 12:32 p.m. |
OK |
GNU C++17 |
TESTS |
102 |
389 |
19046400 |
|
2600 |
|
65931008 |
Phortox |
D |
Nov. 28, 2019, 9:04 p.m. |
OK |
GNU C++17 |
TESTS |
102 |
390 |
23859200 |
|
2600 |
|
64755112 |
user202729_ |
D |
Nov. 12, 2019, 4:38 p.m. |
OK |
GNU C++17 |
TESTS |
102 |
420 |
13824000 |
|
2600 |
|
50550657 |
I_love_Harpae |
D |
Feb. 27, 2019, 3:51 a.m. |
OK |
Java 8 |
TESTS |
102 |
748 |
40243200 |
|
2600 |
|
50550861 |
I_love_Harpae |
D |
Feb. 27, 2019, 4:07 a.m. |
OK |
Java 8 |
TESTS |
102 |
764 |
40243200 |
|
2600 |
|
26874932 |
Aemon |
D |
May 5, 2017, 7:12 a.m. |
OK |
Java 8 |
TESTS |
102 |
811 |
16588800 |
|
2600 |
|
26876012 |
hama-du |
D |
May 5, 2017, 8:18 a.m. |
OK |
Java 8 |
TESTS |
102 |
842 |
25600000 |
|
2600 |
|
50549144 |
BiIIy |
D |
Feb. 27, 2019, 1:58 a.m. |
OK |
Java 8 |
TESTS |
102 |
888 |
38297600 |
|
2600 |
|
26857449 |
uwi |
D |
May 4, 2017, 4:10 p.m. |
OK |
Java 8 |
TESTS |
102 |
967 |
34713600 |
|
2600 |
|
26860759 |
tbuzzelli |
D |
May 4, 2017, 4:34 p.m. |
OK |
Java 8 |
TESTS |
102 |
1045 |
40652800 |
|
2600 |
|
26885541 |
meijun |
D |
May 5, 2017, 4:55 p.m. |
OK |
Java 8 |
TESTS |
102 |
1340 |
43827200 |
|
2600 |
|
26864747 |
Slamur |
D |
May 4, 2017, 6:23 p.m. |
OK |
Java 8 |
TESTS |
102 |
1544 |
45772800 |
|
2600 |
|
27100616 |
ChrisWu |
D |
May 14, 2017, 4:44 a.m. |
OK |
Java 8 |
TESTS |
102 |
1730 |
47616000 |
|
2600 |
|
26877945 |
camypaper |
D |
May 5, 2017, 10:19 a.m. |
OK |
MS C# |
TESTS |
102 |
218 |
22016000 |
|
2600 |
|
26903963 |
NVAL |
D |
May 6, 2017, 2:52 p.m. |
OK |
MS C++ |
TESTS |
102 |
327 |
14745600 |
|
2600 |
|
26860203 |
Perforator |
D |
May 4, 2017, 4:30 p.m. |
OK |
MS C++ |
TESTS |
102 |
343 |
29184000 |
|
2600 |
|
69618945 |
vjudge4 |
D |
Jan. 27, 2020, 2:01 p.m. |
OK |
MS C++ |
TESTS |
102 |
436 |
15257600 |
|
2600 |
|
26865164 |
Filyan |
D |
May 4, 2017, 6:37 p.m. |
OK |
MS C++ |
TESTS |
102 |
592 |
23756800 |
|
2600 |
remove filters
Back to search problems