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
Vova and Marina love offering puzzles to each other. Today Marina offered Vova to cope with the following task. Vova has a non-directed graph consisting of n vertices and m edges without loops and multiple edges. Let's define the operation of contraction two vertices a and b that are not connected by an edge . As a result of this operation vertices a and b are deleted and instead of them a new vertex x is added into the graph, and also edges are drawn from it to all vertices that were connected with a or with b (specifically, if the vertex was connected with both a and b , then also exactly one edge is added from x to it). Thus, as a result of contraction again a non-directed graph is formed, it contains no loops nor multiple edges, and it contains ( n - 1) vertices. Vova must perform the contraction an arbitrary number of times to transform the given graph into a chain of the maximum length. A chain of length k ( k ≥ 0 ) is a connected graph whose vertices can be numbered with integers from 1 to k + 1 so that the edges of the graph connect all pairs of vertices ( i , i + 1) ( 1 ≤ i ≤ k ) and only them. Specifically, the graph that consists of one vertex is a chain of length 0 . The vertices that are formed as a result of the contraction are allowed to be used in the following operations of contraction . Help Vova cope with his girlfriend's task. Find the maximum length of the chain that can be obtained from the resulting graph or else determine that it is impossible to obtain the chain. The first line contains two integers n , m ( 1 ≤ n ≤ 1000 , 0 ≤ m ≤ 100 000 ) — the number of vertices and the number of edges in the original graph. Next m lines contain the descriptions of edges in the format a i , b i ( 1 ≤ a i , b i ≤ n , a i ≠ b i ), which means that there is an edge between vertices a i and b i . It is guaranteed that there is at most one edge between each pair of vertexes. If it is impossible to obtain a chain from the given graph, print - 1 . Other |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
|
11058702 |
daidailanlan |
E |
May 10, 2015, 1:05 a.m. |
OK |
GNU C++ |
TESTS |
50 |
62 |
2457600 |
|
2600 |
|
40986673 |
ReaLNero1 |
E |
July 30, 2018, 8:41 p.m. |
OK |
GNU C++ |
TESTS |
50 |
78 |
2457600 |
|
2600 |
|
11066145 |
daidailanlan |
E |
May 10, 2015, 8:59 p.m. |
OK |
GNU C++ |
TESTS |
50 |
78 |
2457600 |
|
2600 |
|
11273982 |
Dylans |
E |
May 26, 2015, 5:57 a.m. |
OK |
GNU C++ |
TESTS |
50 |
156 |
2252800 |
|
2600 |
|
10987889 |
ainta |
E |
May 3, 2015, 5:38 p.m. |
OK |
GNU C++ |
TESTS |
50 |
156 |
2252800 |
|
2600 |
|
30798190 |
randomstring |
E |
Sept. 28, 2017, 7:59 a.m. |
OK |
GNU C++ |
TESTS |
50 |
156 |
2355200 |
|
2600 |
|
13904311 |
130705009 |
E |
Oct. 27, 2015, 7:23 p.m. |
OK |
GNU C++ |
TESTS |
50 |
171 |
2252800 |
|
2600 |
|
11414723 |
aaaaajack |
E |
June 4, 2015, 2:15 p.m. |
OK |
GNU C++ |
TESTS |
50 |
171 |
2252800 |
|
2600 |
|
13609693 |
Hachiikung |
E |
Oct. 14, 2015, 3:40 p.m. |
OK |
GNU C++ |
TESTS |
50 |
171 |
2355200 |
|
2600 |
|
12299672 |
vjudge2 |
E |
Aug. 1, 2015, 6:15 a.m. |
OK |
GNU C++ |
TESTS |
50 |
171 |
2355200 |
|
2600 |
|
44830798 |
xymtxdy |
E |
Oct. 25, 2018, 8:22 a.m. |
OK |
GNU C++11 |
TESTS |
50 |
156 |
2355200 |
|
2600 |
|
44675677 |
yasugongshang |
E |
Oct. 22, 2018, 4:18 a.m. |
OK |
GNU C++11 |
TESTS |
50 |
156 |
2355200 |
|
2600 |
|
44673630 |
luogu_bot5 |
E |
Oct. 22, 2018, 12:41 a.m. |
OK |
GNU C++11 |
TESTS |
50 |
156 |
2355200 |
|
2600 |
|
38645251 |
zhouyuyang |
E |
May 27, 2018, 1:29 a.m. |
OK |
GNU C++11 |
TESTS |
50 |
156 |
2355200 |
|
2600 |
|
12878140 |
polequoll |
E |
Sept. 6, 2015, 11:03 p.m. |
OK |
GNU C++11 |
TESTS |
50 |
156 |
2355200 |
|
2600 |
|
10987208 |
tuna_salad |
E |
May 3, 2015, 5:14 p.m. |
OK |
GNU C++11 |
TESTS |
50 |
156 |
2355200 |
|
2600 |
|
44674967 |
yasugongshang |
E |
Oct. 22, 2018, 2:46 a.m. |
OK |
GNU C++11 |
TESTS |
50 |
171 |
2355200 |
|
2600 |
|
44673629 |
emoairx |
E |
Oct. 22, 2018, 12:41 a.m. |
OK |
GNU C++11 |
TESTS |
50 |
171 |
2355200 |
|
2600 |
|
12606616 |
Malinovsky239 |
E |
Aug. 19, 2015, 4:57 p.m. |
OK |
GNU C++11 |
TESTS |
50 |
171 |
2355200 |
|
2600 |
|
12095035 |
newbeginBKB |
E |
July 17, 2015, 12:15 p.m. |
OK |
GNU C++11 |
TESTS |
50 |
171 |
2355200 |
|
2600 |
|
48024248 |
vjudge5 |
E |
Jan. 6, 2019, 8 a.m. |
OK |
GNU C++14 |
TESTS |
50 |
171 |
2252800 |
|
2600 |
|
59838634 |
cdes58042169 |
E |
Sept. 1, 2019, 6:02 a.m. |
OK |
GNU C++14 |
TESTS |
50 |
171 |
2355200 |
|
2600 |
|
47676440 |
U_U |
E |
Dec. 29, 2018, 9:24 a.m. |
OK |
GNU C++14 |
TESTS |
50 |
171 |
2355200 |
|
2600 |
|
60245580 |
Retro3014 |
E |
Sept. 8, 2019, 2:20 a.m. |
OK |
GNU C++14 |
TESTS |
50 |
171 |
2457600 |
|
2600 |
|
30744460 |
InvUsr |
E |
Sept. 26, 2017, 8:31 a.m. |
OK |
GNU C++14 |
TESTS |
50 |
171 |
2457600 |
|
2600 |
|
28181541 |
Juanito98 |
E |
July 1, 2017, 12:08 a.m. |
OK |
GNU C++14 |
TESTS |
50 |
171 |
4300800 |
|
2600 |
|
59653468 |
lawfung |
E |
Aug. 29, 2019, 9:17 a.m. |
OK |
GNU C++14 |
TESTS |
50 |
171 |
7168000 |
|
2600 |
|
49962508 |
sepehr81 |
E |
Feb. 15, 2019, 6:57 p.m. |
OK |
GNU C++14 |
TESTS |
50 |
186 |
2355200 |
|
2600 |
|
31252936 |
vjudge5 |
E |
Oct. 12, 2017, 3:49 p.m. |
OK |
GNU C++14 |
TESTS |
50 |
186 |
2457600 |
|
2600 |
|
49843792 |
vjudge1 |
E |
Feb. 12, 2019, 8:01 p.m. |
OK |
GNU C++14 |
TESTS |
50 |
186 |
2560000 |
|
2600 |
|
68618005 |
ImForbiddenToSayILoveYou |
E |
Jan. 11, 2020, 6:14 p.m. |
OK |
GNU C++17 |
TESTS |
50 |
171 |
2355200 |
|
2600 |
|
49363960 |
crathva |
E |
Feb. 2, 2019, 2:10 p.m. |
OK |
GNU C++17 |
TESTS |
50 |
171 |
2355200 |
|
2600 |
|
65278448 |
hjk1030 |
E |
Nov. 18, 2019, 3:40 a.m. |
OK |
GNU C++17 |
TESTS |
50 |
171 |
2457600 |
|
2600 |
|
64672661 |
ruo |
E |
Nov. 11, 2019, 6:42 a.m. |
OK |
GNU C++17 |
TESTS |
50 |
171 |
2457600 |
|
2600 |
|
58943041 |
Pankin |
E |
Aug. 17, 2019, 7:45 a.m. |
OK |
GNU C++17 |
TESTS |
50 |
171 |
2457600 |
|
2600 |
|
59848136 |
baluteshih |
E |
Sept. 1, 2019, 10:22 a.m. |
OK |
GNU C++17 |
TESTS |
50 |
186 |
2355200 |
|
2600 |
|
64682016 |
RUSH_D_CAT |
E |
Nov. 11, 2019, 10:26 a.m. |
OK |
GNU C++17 |
TESTS |
50 |
186 |
2457600 |
|
2600 |
|
47809811 |
AliShahali1382 |
E |
Jan. 1, 2019, 10:26 a.m. |
OK |
GNU C++17 |
TESTS |
50 |
186 |
2560000 |
|
2600 |
|
59885530 |
edisonhello |
E |
Sept. 2, 2019, 7:45 a.m. |
OK |
GNU C++17 |
TESTS |
50 |
187 |
2355200 |
|
2600 |
|
59813116 |
knia |
E |
Aug. 31, 2019, 2:17 p.m. |
OK |
GNU C++17 |
TESTS |
50 |
187 |
2355200 |
|
2600 |
|
10990588 |
og.kostya |
E |
May 3, 2015, 7:51 p.m. |
OK |
Java 7 |
TESTS |
50 |
2479 |
0 |
|
2600 |
|
10990432 |
og.kostya |
E |
May 3, 2015, 7:27 p.m. |
OK |
Java 7 |
TESTS |
50 |
2495 |
0 |
|
2600 |
|
10990532 |
av_life |
E |
May 3, 2015, 7:42 p.m. |
OK |
Java 7 |
TESTS |
50 |
2964 |
0 |
|
2600 |
|
56431100 |
7dan |
E |
July 2, 2019, 12:04 p.m. |
OK |
Java 8 |
TESTS |
50 |
576 |
0 |
|
2600 |
|
10990603 |
av_life |
E |
May 3, 2015, 7:52 p.m. |
OK |
Java 8 |
TESTS |
50 |
2527 |
0 |
|
2600 |
|
10990582 |
av_life |
E |
May 3, 2015, 7:50 p.m. |
OK |
Java 8 |
TESTS |
50 |
2605 |
0 |
|
2600 |
|
10990552 |
av_life |
E |
May 3, 2015, 7:45 p.m. |
OK |
Java 8 |
TESTS |
50 |
2667 |
0 |
|
2600 |
|
10988424 |
Egor |
E |
May 3, 2015, 5:58 p.m. |
OK |
Java 8 |
TESTS |
50 |
2823 |
0 |
|
2600 |
|
44174728 |
vjudge5 |
E |
Oct. 12, 2018, 8:14 a.m. |
OK |
MS C++ |
TESTS |
50 |
234 |
2150400 |
|
2600 |
|
12302998 |
HappyNewYearMike |
E |
Aug. 1, 2015, 11:38 a.m. |
OK |
MS C++ |
TESTS |
50 |
296 |
14643200 |
|
2600 |
|
11120799 |
AleksanderBalobanov |
E |
May 16, 2015, 8:58 p.m. |
OK |
MS C++ |
TESTS |
50 |
296 |
14643200 |
|
2600 |
remove filters
Back to search problems