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"You have n chains, the i -th chain consists of c_i vertices. Vertices in each chain are numbered independently from 1 to c_i along the chain. In other words, the i -th chain is the undirected graph with c_i vertices and (c_i - 1) edges connecting the j -th and the (j + 1) -th vertices for each 1 <= j < c_i . Now you decided to unite chains in one graph in the following way: Calculate the length of the longest simple cycle in the resulting graph. A simple cycle is a chain where the first and last vertices are connected as well. If you travel along the simple cycle, each vertex of this cycle will be visited exactly once. The first line contains a single integer t ( 1 <= t <= 1000 ) -- the number of test cases. The first line of each test case contains the single integer n ( 2 <= n <= 10^5 ) -- the number of chains you have. The second line of each test case contains n integers c_1, c_2, ... , c_n ( 2 <= c_i <= 10^9 ) -- the number of vertices in the corresponding chains. The third line of each test case contains n integers a_1, a_2, ... , a_n ( a_1 = -1 ; 1 <= a_i <= c_{i - 1} ). The fourth line of each test case contains n integers b_1, b_2, ... , b_n ( b_1 = -1 ; 1 <= b_i <= c_{i - 1} ). Both a_1 and b_1 are equal to -1 , they aren't used in graph building and given just for index consistency. It's guaranteed that the sum of n over all test cases doesn't exceed 10^5 . For each test case, print the length of the longest simple cycle. In the first test case, the longest simple cycle is shown below: We can't increase it with the first chain, since in such case it won't be simple -- the vertex 2 on the second chain will break simplicity. "... |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
105944974 |
Chiaro |
C |
Jan. 29, 2021, 5:10 p.m. |
OK |
GNU C++11 |
TESTS |
9 |
30 |
2457600 |
|
|
105972821 |
chengni |
C |
Jan. 30, 2021, 2:24 a.m. |
OK |
GNU C++11 |
TESTS |
9 |
30 |
48537600 |
|
|
105946615 |
fishcathu. |
C |
Jan. 29, 2021, 5:23 p.m. |
OK |
GNU C++11 |
TESTS |
9 |
31 |
1228800 |
|
|
105941501 |
mumei |
C |
Jan. 29, 2021, 4:48 p.m. |
OK |
GNU C++11 |
TESTS |
9 |
31 |
1228800 |
|
|
105974957 |
SOCAER |
C |
Jan. 30, 2021, 3:19 a.m. |
OK |
GNU C++11 |
TESTS |
9 |
31 |
2457600 |
|
|
105935064 |
myx12345 |
C |
Jan. 29, 2021, 4:29 p.m. |
OK |
GNU C++11 |
TESTS |
9 |
31 |
2662400 |
|
|
105981174 |
vjudge1 |
C |
Jan. 30, 2021, 5:36 a.m. |
OK |
GNU C++11 |
TESTS |
9 |
31 |
4812800 |
|
|
105980535 |
vjudge2 |
C |
Jan. 30, 2021, 5:26 a.m. |
OK |
GNU C++11 |
TESTS |
9 |
31 |
4812800 |
|
|
105946438 |
Spacelessd |
C |
Jan. 29, 2021, 5:22 p.m. |
OK |
GNU C++11 |
TESTS |
9 |
31 |
4812800 |
|
|
105970662 |
ACM_killer |
C |
Jan. 30, 2021, 1:19 a.m. |
OK |
GNU C++11 |
TESTS |
9 |
31 |
10444800 |
|
|
remove filters
Back to search problems