CT35102

Cobbler's bridges Reckoning

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

At the gull cliffs of Screech Point, Cobbler records each bridges in a worn leather ledger. The guild wants answers, not guesses. Task: Edges u -> v mean u must come before v. Print the lexicographically smallest valid ordering of the n jobs (space-separated), or IMPOSSIBLE if a cycle exists. Input format: First line: n and m. Next m lines: u v. Output format: Print the order or IMPOSSIBLE. Constraints: 1 <= n <= 1444; 0 <= m <= 1444.

Example 1:

Input: 906 21 16 791 291 504 257 736 6 281 813 839 699 803 796 814 339 375 283 492 62 459 493 599 19 309 521 565 515 833 248 624 293 562 413 698 362 832 526 693 188 191 175 431
Output: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 …

Example 2:

Input: 743 1070 118 449 126 257 358 673 479 718 681 743 213 304 540 661 430 463 76 268 73 559 243 522 302 415 380 581 85 156 154 369 12 324 73 406 647 684 403 438 296 423 394 602 194 439 656 675 12 39 271 397 8 22 120 273 22 715 296 427 70 708 127 587 128 512 492 513 252 562 100 719 447 740 7 51 120 578 51 428 53 382 651 655 158 644 421 426 426 448 257 697 131 561 69 472 627 715 182 524 10 342 401 616 169 731 410 695 433 487 90 725 117 594 52 431 117 623 69 337 279 491 179 441 76 100 258 397 335 379 442 607 196 418 655 716 461 594 441 541 96 503 291 735 34 364 163 719 206 262 77 311 274 672 304 487 11 163 154 701 126 516 79 459 71 653 79 481 232 630 550 651 21 59 24 136 42 258 178 182 466 509 396 584 145 430 8 134 176 209 30 289 383 584 286 698 361 571 99 203 587 606 35 544 248 523 316 525 336 41…
Output: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 …

Example 3:

Input: 1 0
Output: 1

Constraints:

1 <= n <= 1444; 0 <= m <= 1444.

Loading...
Test Cases:No test cases
No test cases available.
Cobbler's bridges Reckoning - MEDIUM Coding Problem | CodeTikki