Kotlin Heroes: Episode 4

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
1346 Kotlin Heroes: Episode 4 FINISHED False 9000 146589911 May 29, 2020, 2:35 p.m.

Problems

Solved$
Index
Name
Type
Tags
Community Tag
Rating
( 383 ) E Magic Tricks PROGRAMMING *special dp graphs 1700

B'Masha is going to participate in a talent show conducted by the university she studies at. She wants to impress the audience with lots of different magic tricks! For one of her tricks, she uses n sponge balls, one of which is a special one. First, she arranges the balls in a row in such a way that the special ball is put on position k (positions are numbered from 1 to n from left to right). After that, she performs m swaps: during the i -th swap, she chooses the ball on position x_i and the ball on position y_i , and swaps them. Since Masha is a magician, she fakes some of her actions to trick the audience -- when she starts performing a swap, she may fake it, so it is not performed (but it looks like it is performed for the audience). There are no constraints on which swaps Masha should fake or should actually perform -- for example, she may fake all of the swaps, or even not fake anything at all. For the trick to work perfectly, the special ball should end up on a specific position -- Masha has not decided yet, which position is perfect. Since faking swaps is difficult, for each position she wants to know the minimum number of swaps she has to fake so that the special ball ends up there. Unfortunately, Masha is a magician, neither a mathematician nor a programmer. So she needs your help in calculating what she wants! The first line contains three integers n , m and k ( 2 <= n <= 2 cdot 10^5 ; 1 <= m <= 2 cdot 10^5 ; 1 <= k <= n ) -- the number of balls, the number of swaps and the initial position of the special ball, respectively. Then m lines follow, the i -th line contains two integers x_i and y_i ( 1 <= x_i, y_i <= n ; x_i ne y_i ) denoting the i -th swap. Print n integers. The i -th integer should be the minimum number of swaps Masha has to fake so the special ball ends up on position i (or -1 , if M'...

Tutorials

Kotlin Heroes: Episode 4 — Editorial

Submissions

Submission Id
Author(s)
Index
Submitted
Verdict
Language
Test Set
Tests Passed
Time taken (ms)
Memory Consumed (bytes)
Tags
Rating
81904192 icebound E May 29, 2020, 3:39 p.m. OK Kotlin TESTS 47 140 0 1700
81912659 sarthakmanna E May 29, 2020, 4:55 p.m. OK Kotlin TESTS 47 155 0 1700
81902882 Egor E May 29, 2020, 3:29 p.m. OK Kotlin TESTS 47 171 0 1700
81903026 Jatana E May 29, 2020, 3:30 p.m. OK Kotlin TESTS 47 202 0 1700
81902178 Taran_1407 E May 29, 2020, 3:24 p.m. OK Kotlin TESTS 47 202 0 1700
81901699 timf1089 E May 29, 2020, 3:21 p.m. OK Kotlin TESTS 47 202 0 1700
81899897 DeadInsideOnTest993 E May 29, 2020, 3:08 p.m. OK Kotlin TESTS 47 202 0 1700
82310113 gwq2017 E June 2, 2020, 1:08 p.m. OK Kotlin TESTS 47 217 0 1700
81901054 sokian E May 29, 2020, 3:16 p.m. OK Kotlin TESTS 47 217 0 1700
81903281 Spheniscine E May 29, 2020, 3:32 p.m. OK Kotlin TESTS 47 217 5324800 1700

remove filters

Back to search problems