CT44533

Jaya's Ledger of tunnels

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Jaya the scribe watches over the acacia flats of Thornveld's stores of tunnels. A careful computation stands between order and chaos. Task: Print YES if the directed graph contains a cycle, otherwise NO. Input format: First line: n and m. Next m lines: u v (directed). Output format: Print YES or NO. Constraints: 1 <= n <= 1257; 0 <= m <= 1257.

Example 1:

Input: 131 1020 42 114 37 87 99 76 22 121 8 77 113 102 105 11 102 40 89 36 15 96 100 14 57 34 122 121 3 92 55 125 81 89 24 41 10 19 6 77 99 17 87 24 46 21 17 78 92 128 85 18 106 103 36 85 35 116 102 7 29 101 71 119 22 84 121 53 122 59 46 63 3 94 36 72 24 7 57 97 105 126 63 20 76 51 130 68 37 3 20 8 4 79 53 81 2 85 76 66 115 24 111 101 20 63 21 89 13 97 8 17 36 29 56 103 98 111 14 41 126 53 51 72 8 26 82 7 15 118 72 125 114 109 88 54 66 8 74 15 119 106 28 46 63 57 89 26 20 43 118 72 66 26 20 54 108 47 49 31 112 122 41 95 27 117 29 18 27 122 76 102 88 117 126 87 36 109 80 43 96 57 2 126 12 104 23 36 53 48 101 18 72 100 61 10 123 86 15 54 15 7 125 62 108 61 103 29 39 49 106 93 30 65 121 78 19 96 121 128 67 98 84 85 80 1 50 26 46 40 49 107 7 75 71 77 105 63 71 54 30 25 93 10 50 28 112 55 39 74 121 31…
Output: YES

Example 2:

Input: 669 1110 92 629 611 597 331 1 100 625 146 347 334 434 405 141 555 13 530 256 604 424 23 376 105 31 565 392 72 153 197 47 181 193 512 361 512 528 623 512 235 259 603 513 25 523 462 87 226 332 416 516 447 601 330 570 484 194 606 591 70 450 266 461 455 109 620 378 446 143 365 161 310 424 616 50 504 616 13 493 610 67 377 621 60 175 281 213 278 201 98 161 9 130 361 652 139 91 419 29 168 144 606 201 539 345 368 99 464 450 280 139 375 93 435 255 200 580 171 301 194 169 510 386 224 230 331 166 426 595 266 533 79 13 610 502 378 623 274 140 650 361 153 669 218 607 73 397 443 135 594 232 322 523 423 77 142 211 152 554 295 122 203 217 617 544 606 613 55 302 162 540 77 65 329 294 265 142 629 288 483 658 314 23 580 459 54 594 380 604 602 244 331 243 140 14 159 24 548 195 167 491 319 159 536 131 399 182 …
Output: YES

Example 3:

Input: 17 110 13 2 6 13 15 6 8 7 4 10 8 12 2 17 1 6 17 4 9 11 8 1 3 5 7 4 1 15 4 13 6 7 8 2 16 14 12 7 14 12 2 5 13 10 5 9 3 2 17 2 3 14 13 7 9 15 17 8 3 4 4 17 11 14 17 10 7 3 12 5 4 3 13 4 11 2 15 7 6 12 1 4 3 12 1 13 5 15 4 5 9 1 7 11 16 1 8 6 10 8 2 6 12 10 13 11 8 17 8 10 14 1 2 13 15 16 12 17 12 11 2 12 16 13 17 14 1 12 16 2 1 3 3 10 16 6 7 10 1 5 15 9 13 3 14 7 11 13 13 6 6 3 1 8 10 16 4 2 5 2 6 1 4 7 8 4 7 16 7 6 1 11 13 8 14 4 15 13 17 12 8 3 10 15 10 6 17 6 3 16 9 6 14 3 15 10 3 9 6 16 5 8 14 8 8 11 6 10 1 17 1 2 6 14 14 13 14 10 4 14
Output: YES

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Jaya's Ledger of tunnels - MEDIUM Coding Problem | CodeTikki