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
Berland consists of n cities and m bidirectional roads connecting pairs of cities. There is no road connecting a city to itself, and between any pair of cities there is no more than one road. It is possible to reach any city from any other moving along roads. Currently Mr. President is in the city s and his destination is the city t . He plans to move along roads from s to t ( s ≠ t ). That's why Ministry of Fools and Roads has difficult days. The minister is afraid that Mr. President could get into a traffic jam or get lost. Who knows what else can happen! To be sure that everything goes as planned, the minister decided to temporarily make all roads one-way. So each road will be oriented in one of two possible directions. The following conditions must be satisfied: There should be no cycles along roads after orientation. The city s should be the only such city that all its roads are oriented out (i.e. there are no ingoing roads to the city s and the city s is the only such city). The city t should be the only such city that all its roads are oriented in (i.e. there are no outgoing roads from the city t and the city t is the only such city). Help the minister solve his problem. Write a program to find any such orientation of all roads or report that no solution exists. Each test in this problem contains one or more test cases to solve. The first line of the input contains positive number T — the number of cases to solve. Each case starts with a line containing four integers n , m , s and t ( 2 ≤ n ≤ 4·10 5 , 1 ≤ m ≤ 10 6 , 1 ≤ s , t ≤ n , s ≠ t ) — the number of cities, the number of roads and indices of departure and destination cities. The cities are numbered from 1 to n . The following m lines contain roads, one road per line. Each road is given as two integer numbers x j , y j ( 1 ≤ x j , y j ≤ n , x j ≠ y j ), which means that the j -th road connects cities x j and y j . There is at most one road between any pair of cities. It is possible to reach any |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
|
22013149 |
jasonvictoryan |
K |
Nov. 3, 2016, 1:16 p.m. |
OK |
GNU C++ |
TESTS |
58 |
982 |
100556800 |
|
3300 |
|
40983305 |
ReaLNero1 |
K |
July 30, 2018, 6:48 p.m. |
OK |
GNU C++ |
TESTS |
58 |
1060 |
100556800 |
|
3300 |
|
21844515 |
vjudge4 |
K |
Oct. 28, 2016, 11:04 a.m. |
OK |
GNU C++ |
TESTS |
58 |
1153 |
142950400 |
|
3300 |
|
26373460 |
Iliaplt |
K |
April 15, 2017, 7:33 a.m. |
OK |
GNU C++ |
TESTS |
58 |
1684 |
212172800 |
|
3300 |
|
21987361 |
lucyanna2018 |
K |
Nov. 2, 2016, 9:50 a.m. |
OK |
GNU C++ |
TESTS |
58 |
1700 |
210124800 |
|
3300 |
|
21910452 |
lukasamkharadze |
K |
Oct. 31, 2016, 11:51 a.m. |
OK |
GNU C++ |
TESTS |
58 |
2745 |
63590400 |
|
3300 |
|
23340162 |
Manchery |
K |
Dec. 26, 2016, 12:44 p.m. |
OK |
GNU C++11 |
TESTS |
58 |
904 |
133939200 |
|
3300 |
|
54503591 |
WOSHIGEPACHONG2 |
K |
May 23, 2019, 1:17 a.m. |
OK |
GNU C++11 |
TESTS |
58 |
1044 |
53657600 |
|
3300 |
|
50238743 |
diamond_duke |
K |
Feb. 20, 2019, 12:01 p.m. |
OK |
GNU C++11 |
TESTS |
58 |
1060 |
53657600 |
|
3300 |
|
36746345 |
zhouyuyang |
K |
March 30, 2018, 12:14 p.m. |
OK |
GNU C++11 |
TESTS |
58 |
1091 |
82022400 |
|
3300 |
|
31500033 |
wangyurzee7 |
K |
Oct. 19, 2017, 7:20 a.m. |
OK |
GNU C++11 |
TESTS |
58 |
1122 |
69836800 |
|
3300 |
|
23920635 |
mggamer |
K |
Jan. 18, 2017, 11:39 a.m. |
OK |
GNU C++11 |
TESTS |
58 |
1153 |
76288000 |
|
3300 |
|
21969679 |
visitWorld |
K |
Nov. 1, 2016, 2:03 p.m. |
OK |
GNU C++11 |
TESTS |
58 |
1185 |
67788800 |
|
3300 |
|
22185503 |
FatalEagle zxqfl y0105w49 |
K |
Nov. 12, 2016, 11:27 p.m. |
OK |
GNU C++11 |
TESTS |
58 |
1185 |
74137600 |
|
3300 |
|
57878406 |
lopare |
K |
July 28, 2019, 6:38 a.m. |
OK |
GNU C++11 |
TESTS |
58 |
1185 |
163942400 |
|
3300 |
|
36245937 |
miaom |
K |
March 13, 2018, 11:23 a.m. |
OK |
GNU C++11 |
TESTS |
58 |
1263 |
165888000 |
|
3300 |
|
22012459 |
funCfans |
K |
Nov. 3, 2016, 12:53 p.m. |
OK |
GNU C++14 |
TESTS |
58 |
1201 |
108134400 |
|
3300 |
|
21840739 |
SssssssssssssbbbBBBB |
K |
Oct. 28, 2016, 7:04 a.m. |
OK |
GNU C++14 |
TESTS |
58 |
1341 |
143052800 |
|
3300 |
|
22005351 |
funCfans |
K |
Nov. 3, 2016, 3:23 a.m. |
OK |
GNU C++14 |
TESTS |
58 |
1450 |
217190400 |
|
3300 |
|
29973089 |
apiadu |
K |
Sept. 1, 2017, 11:51 a.m. |
OK |
GNU C++14 |
TESTS |
58 |
1481 |
62771200 |
|
3300 |
|
49612300 |
black_horse2014 |
K |
Feb. 8, 2019, 2:51 a.m. |
OK |
GNU C++14 |
TESTS |
58 |
1496 |
79769600 |
|
3300 |
|
22408374 |
thjchph4trjnh |
K |
Nov. 22, 2016, 5:26 p.m. |
OK |
GNU C++14 |
TESTS |
58 |
1622 |
94617600 |
|
3300 |
|
22803223 |
maroonrk |
K |
Dec. 8, 2016, 6:42 a.m. |
OK |
GNU C++14 |
TESTS |
58 |
1622 |
109158400 |
|
3300 |
|
22164822 |
chemthan |
K |
Nov. 11, 2016, 3:08 p.m. |
OK |
GNU C++14 |
TESTS |
58 |
1700 |
94515200 |
|
3300 |
|
21719729 |
viesis |
K |
Oct. 23, 2016, 6:42 p.m. |
OK |
GNU C++14 |
TESTS |
58 |
2058 |
141414400 |
|
3300 |
|
21715334 |
1234 |
K |
Oct. 23, 2016, 2:51 p.m. |
OK |
GNU C++14 |
TESTS |
58 |
2058 |
141414400 |
|
3300 |
|
69715193 |
gongsuidashen |
K |
Jan. 29, 2020, 8:44 a.m. |
OK |
GNU C++17 |
TESTS |
58 |
826 |
138547200 |
|
3300 |
|
55555697 |
hjk1030 |
K |
June 14, 2019, 9:45 a.m. |
OK |
GNU C++17 |
TESTS |
58 |
1107 |
138444800 |
|
3300 |
|
62252040 |
ko_osaga |
K |
Oct. 10, 2019, 9:34 a.m. |
OK |
GNU C++17 |
TESTS |
58 |
1450 |
103936000 |
|
3300 |
|
62251452 |
ko_osaga |
K |
Oct. 10, 2019, 9:24 a.m. |
OK |
GNU C++17 |
TESTS |
58 |
1513 |
87961600 |
|
3300 |
|
65767565 |
nitesh_gupta |
K |
Nov. 26, 2019, 6:43 p.m. |
OK |
GNU C++17 |
TESTS |
58 |
1606 |
146227200 |
|
3300 |
|
42364118 |
teapotd |
K |
Sept. 2, 2018, 1:34 p.m. |
OK |
GNU C++17 |
TESTS |
58 |
2947 |
78233600 |
|
3300 |
|
42387093 |
teapotd |
K |
Sept. 2, 2018, 3:32 p.m. |
OK |
GNU C++17 |
TESTS |
58 |
3150 |
80998400 |
|
3300 |
|
30637868 |
AmirKarimi7 |
K |
Sept. 23, 2017, 10:14 a.m. |
OK |
Java 8 |
TESTS |
58 |
2433 |
144998400 |
|
3300 |
|
21883479 |
mmaxio |
K |
Oct. 29, 2016, 9:47 p.m. |
OK |
Java 8 |
TESTS |
58 |
2651 |
144896000 |
|
3300 |
|
21883416 |
mmaxio |
K |
Oct. 29, 2016, 9:40 p.m. |
OK |
Java 8 |
TESTS |
58 |
2698 |
144896000 |
|
3300 |
remove filters
Back to search problems