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 are n districts in the town, the i -th district belongs to the a_i -th bandit gang. Initially, no districts are connected to each other. You are the mayor of the city and want to build n-1 two-way roads to connect all districts (two districts can be connected directly or through other connected districts). If two districts belonging to the same gang are connected directly with a road, this gang will revolt. You don't want this so your task is to build n-1 two-way roads in such a way that all districts are reachable from each other (possibly, using intermediate districts) and each pair of directly connected districts belong to different gangs, or determine that it is impossible to build n-1 roads to satisfy all the conditions. You have to answer t independent test cases. The first line of the input contains one integer t ( 1 <= t <= 500 ) -- the number of test cases. Then t test cases follow. The first line of the test case contains one integer n ( 2 <= n <= 5000 ) -- the number of districts. The second line of the test case contains n integers a_1, a_2, ldots, a_n ( 1 <= a_i <= 10^9 ), where a_i is the gang the i -th district belongs to. It is guaranteed that the sum of n does not exceed 5000 ( sum n <= 5000 ). For each test case, print: For each road i , the condition a[x_i] ne a[y_i] should be satisfied. Also, all districts should be reachable from each other (possibly, using intermediate districts). "... |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
96202310 |
C_Aric |
D |
Oct. 21, 2020, 4:31 a.m. |
OK |
GNU C++11 |
TESTS |
20 |
15 |
0 |
|
|
96203597 |
hnust_liuxin |
D |
Oct. 21, 2020, 4:56 a.m. |
OK |
GNU C++11 |
TESTS |
20 |
15 |
204800 |
|
|
96168157 |
mobarak_aiub |
D |
Oct. 20, 2020, 4:49 p.m. |
OK |
GNU C++11 |
TESTS |
20 |
30 |
204800 |
|
|
96195755 |
HHHEN |
D |
Oct. 21, 2020, 1:49 a.m. |
OK |
GNU C++11 |
TESTS |
20 |
30 |
819200 |
|
|
96204421 |
MeshTag |
D |
Oct. 21, 2020, 5:10 a.m. |
OK |
GNU C++11 |
TESTS |
20 |
31 |
0 |
|
|
96201921 |
MengWH |
D |
Oct. 21, 2020, 4:22 a.m. |
OK |
GNU C++11 |
TESTS |
20 |
31 |
0 |
|
|
96199964 |
wddmahe |
D |
Oct. 21, 2020, 3:36 a.m. |
OK |
GNU C++11 |
TESTS |
20 |
31 |
0 |
|
|
96197382 |
TheBlueSnake |
D |
Oct. 21, 2020, 2:35 a.m. |
OK |
GNU C++11 |
TESTS |
20 |
31 |
0 |
|
|
96195667 |
zhujunchao |
D |
Oct. 21, 2020, 1:46 a.m. |
OK |
GNU C++11 |
TESTS |
20 |
31 |
0 |
|
|
96194539 |
lijiatu |
D |
Oct. 21, 2020, 1:08 a.m. |
OK |
GNU C++11 |
TESTS |
20 |
31 |
0 |
|
|
96207653 |
yefim123 |
D |
Oct. 21, 2020, 6:02 a.m. |
OK |
GNU C++14 |
TESTS |
20 |
31 |
0 |
|
|
96206934 |
Greatest789 |
D |
Oct. 21, 2020, 5:50 a.m. |
OK |
GNU C++14 |
TESTS |
20 |
31 |
0 |
|
|
96206421 |
Second_id |
D |
Oct. 21, 2020, 5:42 a.m. |
OK |
GNU C++14 |
TESTS |
20 |
31 |
0 |
|
|
96205735 |
rez_ |
D |
Oct. 21, 2020, 5:31 a.m. |
OK |
GNU C++14 |
TESTS |
20 |
31 |
0 |
|
|
96204796 |
Flukey |
D |
Oct. 21, 2020, 5:16 a.m. |
OK |
GNU C++14 |
TESTS |
20 |
31 |
0 |
|
|
96203116 |
LongDo2k |
D |
Oct. 21, 2020, 4:48 a.m. |
OK |
GNU C++14 |
TESTS |
20 |
31 |
0 |
|
|
96200189 |
saurav1717 |
D |
Oct. 21, 2020, 3:40 a.m. |
OK |
GNU C++14 |
TESTS |
20 |
31 |
0 |
|
|
96199538 |
THEtoshit |
D |
Oct. 21, 2020, 3:26 a.m. |
OK |
GNU C++14 |
TESTS |
20 |
31 |
0 |
|
|
96196142 |
vjudge4 |
D |
Oct. 21, 2020, 2:01 a.m. |
OK |
GNU C++14 |
TESTS |
20 |
31 |
0 |
|
|
96195007 |
ojhaakshat |
D |
Oct. 21, 2020, 1:23 a.m. |
OK |
GNU C++14 |
TESTS |
20 |
31 |
0 |
|
|
remove filters
Back to search problems