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.
ContestId |
Name |
Phase |
Frozen |
Duration (Seconds) |
Relative Time |
Start Time |
|---|---|---|---|---|---|---|
| 81 | Yandex.Algorithm Open 2011: Qualification 1 | FINISHED | False | 7200 | 471920423 | May 4, 2011, 5 a.m. |
Solved |
Index |
Name |
Type |
Tags |
Community Tag |
Rating |
|---|---|---|---|---|---|---|
| ( 398 ) | E | Pairs | PROGRAMMING | dfs and similar dp dsu graphs implementation trees | 2600 |
There are n students in Polycarp's class (including himself). A few days ago all students wrote an essay "My best friend". Each student's essay was dedicated to one of the students of class, to his/her best friend. Note that student b 's best friend is not necessarily student a , if a 's best friend is b . And now the teacher leads the whole class to the museum of the history of sports programming. Exciting stories of legendary heroes await the students: tourist, Petr, tomek, SnapDragon — that's who they will hear about! The teacher decided to divide students into pairs so that each pair consisted of a student and his best friend. She may not be able to split all the students into pairs, it's not a problem — she wants to pick out the maximum number of such pairs. If there is more than one variant of doing so, she wants to pick out the pairs so that there were as much boy-girl pairs as possible. Of course, each student must not be included in more than one pair. The first line contains an integer n ( 2 ≤ n ≤ 10 5 ), n is the number of students per class. Next, n lines contain information about the students, one per line. Each line contains two integers f i , s i ( 1 ≤ f i ≤ n , f i ≠ i , 1 ≤ s i ≤ 2 ), where f i is the number of i -th student's best friend and s i denotes the i -th pupil's sex ( s i = 1 for a boy and s i = 2 for a girl). Print on the first line two numbers t , e , where t is the maximum number of formed pairs, and e is the maximum number of boy-girl type pairs among them. Then print t lines, each line must contain a pair a i , b i ( 1 ≤ a i , b i ≤ n ), they are numbers of pupils in the i -th pair. Print the pairs in any order. Print the numbers in pairs in any order. If there are several solutions, output any of them. The picture corresponds to the first sample. On the picture rhomb stand for boys, squares stand for girls, arrows lead from a pupil to his/her best friend. Bold non-dashed arrows stand for pairs in the answer. |
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 1159541 | zanoes | E | Feb. 9, 2012, 12:08 p.m. | OK | FPC | TESTS | 60 | 110 | 22220800 | 2600 | |
| 2509072 | luogan | E | Nov. 5, 2012, 3:41 a.m. | OK | FPC | TESTS | 60 | 156 | 16588800 | 2600 | |
| 10346521 | vjudge5 | E | March 19, 2015, 8:39 a.m. | OK | FPC | TESTS | 60 | 248 | 12492800 | 2600 | |
| 1144665 | mage | E | Feb. 2, 2012, 9:10 p.m. | OK | GNU C | TESTS | 60 | 160 | 11366400 | 2600 | |
| 2928895 | Leo_Yu | E | Jan. 16, 2013, 7:52 a.m. | OK | GNU C++ | TESTS | 60 | 62 | 12390400 | 2600 | |
| 28005989 | vjudge4 | E | June 24, 2017, 1:21 p.m. | OK | GNU C++ | TESTS | 60 | 62 | 14233600 | 2600 | |
| 28185172 | iwtywai2005 | E | July 1, 2017, 6:25 a.m. | OK | GNU C++ | TESTS | 60 | 62 | 14336000 | 2600 | |
| 40992752 | ReaLNero1 | E | July 31, 2018, 1:32 a.m. | OK | GNU C++ | TESTS | 60 | 77 | 12185600 | 2600 | |
| 14187226 | 130705009 | E | Nov. 10, 2015, 4:23 p.m. | OK | GNU C++ | TESTS | 60 | 77 | 12185600 | 2600 | |
| 15142237 | HappyNewYearMike | E | Dec. 31, 2015, 10:13 p.m. | OK | GNU C++ | TESTS | 60 | 78 | 16486400 | 2600 | |
| 20095960 | vjudge3 | E | Aug. 24, 2016, 12:30 a.m. | OK | GNU C++ | TESTS | 60 | 78 | 17305600 | 2600 | |
| 2791160 | asklzxn2 | E | Dec. 18, 2012, 2:33 p.m. | OK | GNU C++ | TESTS | 60 | 93 | 10649600 | 2600 | |
| 13728192 | nxihkke | E | Oct. 19, 2015, 12:45 p.m. | OK | GNU C++ | TESTS | 60 | 93 | 14848000 | 2600 | |
| 21958291 | ziqian | E | Nov. 1, 2016, 6:17 a.m. | OK | GNU C++ | TESTS | 60 | 93 | 17715200 | 2600 | |
| 2857065 | apia | E | Dec. 30, 2012, 1:26 p.m. | OK | GNU C++0x | TESTS | 60 | 171 | 15769600 | 2600 | |
| 430121 | 2222 | E | May 4, 2011, 8:35 a.m. | OK | GNU C++0x | TESTS | 60 | 230 | 19353600 | 2600 | |
| 2472288 | dc. | E | Oct. 30, 2012, 11:52 p.m. | OK | GNU C++0x | TESTS | 60 | 234 | 18124800 | 2600 | |
| 2825631 | CMHJT | E | Dec. 25, 2012, 12:53 p.m. | OK | GNU C++0x | TESTS | 60 | 312 | 28057600 | 2600 | |
| 34301100 | zyding | E | Jan. 19, 2018, 11:52 a.m. | OK | GNU C++11 | TESTS | 60 | 62 | 11776000 | 2600 | |
| 54496567 | WOSHIGEPACHONG2 | E | May 22, 2019, 6:04 p.m. | OK | GNU C++11 | TESTS | 60 | 62 | 12185600 | 2600 | |
| 47887231 | xielinhan | E | Jan. 4, 2019, 1:28 a.m. | OK | GNU C++11 | TESTS | 60 | 62 | 12185600 | 2600 | |
| 34625000 | zyding | E | Jan. 28, 2018, 6:18 a.m. | OK | GNU C++11 | TESTS | 60 | 62 | 17715200 | 2600 | |
| 55586891 | Big_black_jujube | E | June 15, 2019, 10:04 a.m. | OK | GNU C++11 | TESTS | 60 | 62 | 22118400 | 2600 | |
| 34300505 | FizzyDavid | E | Jan. 19, 2018, 11:30 a.m. | OK | GNU C++11 | TESTS | 60 | 77 | 19251200 | 2600 | |
| 34303039 | tqyaaaaaaaang | E | Jan. 19, 2018, 1:01 p.m. | OK | GNU C++11 | TESTS | 60 | 77 | 21811200 | 2600 | |
| 27520481 | 754986421653 | E | June 2, 2017, 9:46 a.m. | OK | GNU C++11 | TESTS | 60 | 78 | 15667200 | 2600 | |
| 34336406 | lzr_010506 | E | Jan. 20, 2018, 3:05 a.m. | OK | GNU C++11 | TESTS | 60 | 78 | 17305600 | 2600 | |
| 33268522 | hawkomg | E | Dec. 15, 2017, 2:57 p.m. | OK | GNU C++11 | TESTS | 60 | 78 | 17305600 | 2600 | |
| 56310828 | Nostalgically | E | June 30, 2019, 2:42 p.m. | OK | GNU C++14 | TESTS | 60 | 62 | 16998400 | 2600 | |
| 56016888 | sorry_im_smurfing | E | June 24, 2019, 10:05 p.m. | OK | GNU C++14 | TESTS | 60 | 78 | 15769600 | 2600 | |
| 64669441 | aeternalis1 | E | Nov. 11, 2019, 4:55 a.m. | OK | GNU C++14 | TESTS | 60 | 93 | 9728000 | 2600 | |
| 62341985 | VahitGuetta | E | Oct. 11, 2019, 5:38 a.m. | OK | GNU C++14 | TESTS | 60 | 93 | 20480000 | 2600 | |
| 34850909 | ascchrvalstr | E | Feb. 2, 2018, 3:10 p.m. | OK | GNU C++14 | TESTS | 60 | 108 | 18329600 | 2600 | |
| 46448366 | ASSWECAN | E | Dec. 1, 2018, 2:50 p.m. | OK | GNU C++14 | TESTS | 60 | 108 | 23756800 | 2600 | |
| 41208009 | boook | E | Aug. 4, 2018, 8:54 a.m. | OK | GNU C++14 | TESTS | 60 | 109 | 15360000 | 2600 | |
| 34533985 | ShakuganSky | E | Jan. 25, 2018, 2:50 a.m. | OK | GNU C++14 | TESTS | 60 | 109 | 17203200 | 2600 | |
| 34533944 | ShakuganSky | E | Jan. 25, 2018, 2:46 a.m. | OK | GNU C++14 | TESTS | 60 | 109 | 17203200 | 2600 | |
| 34266001 | Cyanic | E | Jan. 18, 2018, 4:06 a.m. | OK | GNU C++14 | TESTS | 60 | 109 | 17612800 | 2600 | |
| 62969798 | hjk1030 | E | Oct. 20, 2019, 6:28 a.m. | OK | GNU C++17 | TESTS | 60 | 93 | 13312000 | 2600 | |
| 52059855 | ivan100sic | E | March 30, 2019, 11:07 p.m. | OK | GNU C++17 | TESTS | 60 | 93 | 15360000 | 2600 | |
| 39424496 | ruo | E | June 20, 2018, 2:07 a.m. | OK | GNU C++17 | TESTS | 60 | 108 | 16896000 | 2600 | |
| 46660995 | nthoang | E | Dec. 5, 2018, 7:20 p.m. | OK | GNU C++17 | TESTS | 60 | 108 | 23756800 | 2600 | |
| 43715382 | tkj | E | Oct. 3, 2018, 6:57 a.m. | OK | GNU C++17 | TESTS | 60 | 109 | 15257600 | 2600 | |
| 61089672 | Eran | E | Sept. 22, 2019, 8:24 p.m. | OK | GNU C++17 | TESTS | 60 | 171 | 20684800 | 2600 | |
| 429795 | cerealguy | E | May 4, 2011, 8:01 a.m. | OK | Java 6 | TESTS | 60 | 310 | 50073600 | 2600 | |
| 427595 | pashka | E | May 4, 2011, 6:18 a.m. | OK | Java 6 | TESTS | 60 | 450 | 78131200 | 2600 | |
| 429037 | wata | E | May 4, 2011, 6:55 a.m. | OK | Java 6 | TESTS | 60 | 840 | 88576000 | 2600 | |
| 428102 | Petr | E | May 4, 2011, 6:30 a.m. | OK | Java 6 | TESTS | 60 | 1330 | 134348800 | 2600 | |
| 23785611 | Chapecoense | E | Jan. 13, 2017, 1:38 p.m. | OK | Java 8 | TESTS | 60 | 389 | 65638400 | 2600 | |
| 430581 | maksay | E | May 4, 2011, 10:16 a.m. | OK | MS C++ | TESTS | 60 | 160 | 15052800 | 2600 | |
| 1558696 | emppu | E | April 17, 2012, 12:51 a.m. | OK | MS C++ | TESTS | 60 | 170 | 10956800 | 2600 | |
| 430584 | maksay | E | May 4, 2011, 10:17 a.m. | OK | MS C++ | TESTS | 60 | 170 | 15052800 | 2600 | |
| 429525 | Anton_Lunyov | E | May 4, 2011, 7:47 a.m. | OK | MS C++ | TESTS | 60 | 220 | 13312000 | 2600 | |
| 431550 | KADR | E | May 4, 2011, 3:04 p.m. | OK | MS C++ | TESTS | 60 | 230 | 11059200 | 2600 | |
| 431831 | ardiankp | E | May 4, 2011, 4:24 p.m. | OK | MS C++ | TESTS | 60 | 280 | 20582400 | 2600 | |
| 433751 | good_mood | E | May 6, 2011, 4:39 a.m. | OK | MS C++ | TESTS | 60 | 340 | 21504000 | 2600 | |
| 432715 | ardiankp | E | May 5, 2011, 7:43 a.m. | OK | MS C++ | TESTS | 60 | 420 | 24883200 | 2600 | |
| 432305 | Medium | E | May 4, 2011, 8:29 p.m. | OK | MS C++ | TESTS | 60 | 470 | 19353600 | 2600 | |
| 428908 | Ripatti | E | May 4, 2011, 6:53 a.m. | OK | MS C++ | TESTS | 60 | 530 | 26931200 | 2600 |
Back to search problems