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
B"There was no problem about a cactus at the NERC 2020 online round. That's a bad mistake, so judges decided to fix it. You shall not pass to the World Finals 2021 without solving a problem about a cactus! A cactus is a connected undirected graph in which every edge lies on at most one simple cycle. Intuitively, a cactus is a generalization of a tree where some cycles are allowed. Multiedges (multiple edges between a pair of vertices) and loops (edges that connect a vertex to itself) are not allowed in a cactus. Cher has got a cactus. She calls cactus strong if it is impossible to add an edge to it in such a way that it still remains a cactus. But Cher thinks her cactus is not strong enough. She wants to add the smallest possible number of edges to it to make it strong, i. e. to create a new cactus with the same vertices, so that the original cactus is a subgraph of the new one, and it is impossible to add another edge to it so that the graph remains a cactus. Cher hired you to do this job for her. So... it's on you! The input consists of one or more independent test cases. The first line of each test case contains two integers n and m ( 1 <= n <= 10^5 , 0 <= m <= 10^5 ), where n is the number of vertices in the graph. Vertices are numbered from 1 to n . Edges of the graph are represented by a set of edge-distinct paths, where m is the number of such paths. Each of the following m lines contains a path in the graph. A path starts with an integer number s_i ( 2 <= s_i <= 1000 ) followed by s_i integers from 1 to n . These s_i integers represent vertices of a path. Adjacent vertices in a path are distinct. The path can go through the same vertex multiple times, but every edge is traversed exactly once in the whole test case. There are no multiedges in the graph (there is at most one edge between any two vertices). The last line of the input after all test cases always "... |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
112003160 |
Farhod_Farmon |
C |
April 4, 2021, 12:54 p.m. |
OK |
GNU C++14 |
TESTS |
84 |
311 |
21299200 |
|
|
111993594 |
Yousef_Salama mahmoudbadawy tamp_ |
C |
April 4, 2021, 11:03 a.m. |
OK |
GNU C++17 |
TESTS |
84 |
93 |
14233600 |
|
|
112008329 |
Somil-key |
C |
April 4, 2021, 2:03 p.m. |
OK |
GNU C++17 |
TESTS |
84 |
109 |
17612800 |
|
|
111995933 |
cxaphoenix AlexPanda |
C |
April 4, 2021, 11:31 a.m. |
OK |
GNU C++17 |
TESTS |
84 |
109 |
17612800 |
|
|
112048628 |
sunsiyu |
C |
April 5, 2021, 5:55 a.m. |
OK |
GNU C++17 |
TESTS |
84 |
124 |
18534400 |
|
|
112028489 |
Fedosik |
C |
April 4, 2021, 7:04 p.m. |
OK |
GNU C++17 |
TESTS |
84 |
436 |
50790400 |
|
|
112034362 |
scott_wu ecnerwala ksun48 |
C |
April 4, 2021, 9:36 p.m. |
OK |
GNU C++17 (64) |
TESTS |
84 |
77 |
22425600 |
|
|
112000842 |
noimi math957963 jell |
C |
April 4, 2021, 12:28 p.m. |
OK |
GNU C++17 (64) |
TESTS |
84 |
93 |
26828800 |
|
|
111988038 |
DreamingLeaf |
C |
April 4, 2021, 9:53 a.m. |
OK |
GNU C++17 (64) |
TESTS |
84 |
93 |
33177600 |
|
|
111998607 |
risujiroh kort0n Rubikun |
C |
April 4, 2021, 12:02 p.m. |
OK |
GNU C++17 (64) |
TESTS |
84 |
109 |
31744000 |
|
|
111994603 |
DmitryGrigorev ShadowLight Denisson |
C |
April 4, 2021, 11:15 a.m. |
OK |
GNU C++17 (64) |
TESTS |
84 |
186 |
28160000 |
|
|
111989294 |
chemthan ngfam neko_nyaaaaaaaaaaaaaaaaa |
C |
April 4, 2021, 10:08 a.m. |
OK |
GNU C++17 (64) |
TESTS |
84 |
187 |
38400000 |
|
|
111997211 |
Akulyat okwedook arzhantsev64 |
C |
April 4, 2021, 11:45 a.m. |
OK |
GNU C++17 (64) |
TESTS |
84 |
265 |
36147200 |
|
|
111991431 |
Um_nik KAN Merkurev |
C |
April 4, 2021, 10:35 a.m. |
OK |
GNU C++17 (64) |
TESTS |
84 |
280 |
112025600 |
|
|
111996997 |
yijan Cirno_9baka Juanzhang |
C |
April 4, 2021, 11:43 a.m. |
OK |
GNU C++17 (64) |
TESTS |
84 |
342 |
45158400 |
|
|
remove filters
Back to search problems