CT37133

The corridors Circular Route Puzzle

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Quade inherited the exchange at the basalt cliffs of Obsidian Shore along with its curious bookkeeping system for corridors. Time to make sense of it. 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 <= 2972; 0 <= m <= 2972.

Example 1:

Input: 488 2537 196 147 155 153 245 280 285 1 386 304 26 438 462 257 178 43 24 202 427 203 263 174 4 457 345 166 363 157 468 263 193 120 152 77 341 223 44 161 382 170 482 377 412 187 187 61 246 11 373 178 256 258 176 412 171 385 484 67 142 293 176 276 248 353 303 267 400 248 330 302 202 212 455 452 294 426 367 478 183 303 151 164 67 401 440 454 418 250 458 161 306 480 250 287 348 419 188 344 316 285 343 395 174 227 22 391 320 81 123 148 66 377 9 298 256 17 286 251 39 134 59 60 309 211 375 225 8 381 429 443 403 63 242 118 367 196 49 39 379 408 80 143 218 105 77 152 307 328 324 88 170 346 439 30 442 174 462 404 187 352 171 280 380 35 419 353 336 124 482 337 425 394 319 246 132 441 190 301 104 401 266 304 352 332 225 53 23 415 197 466 426 74 337 154 175 81 178 199 338 158 351 218 449 461 356 98 373 …
Output: YES

Example 2:

Input: 2206 1353 2054 836 1599 46 1162 1718 420 1816 1009 697 660 1019 1503 953 488 930 742 768 846 1288 980 1285 534 310 1697 648 1271 2161 1262 139 105 410 242 1037 837 845 68 1976 788 1532 787 1399 923 1667 449 1159 794 96 1002 1409 598 1863 1329 296 321 387 2138 2091 941 192 635 99 1868 81 83 1168 492 1331 1312 90 449 1264 1673 573 1285 876 1862 1233 573 1677 1118 108 1922 1977 957 1021 872 5 52 1195 2009 780 1251 1711 1135 1593 143 809 392 394 222 39 993 1925 1559 1029 1564 634 2143 1254 1695 2 1831 67 2179 814 2180 111 1549 2098 356 494 157 976 1507 486 1407 1020 759 264 2005 116 1258 1277 1722 1972 895 2095 638 380 2129 1436 1714 618 1386 1015 1378 283 1882 1959 387 1099 1074 2150 1067 1729 2012 1196 731 1697 2175 75 1438 592 616 2118 1462 507 417 1737 1884 1614 1967 1458 1503 2143 956 302…
Output: NO

Example 3:

Input: 755 265 664 118 290 184 359 668 319 471 295 8 538 628 147 649 342 112 362 38 24 105 720 48 575 128 720 34 258 644 55 178 141 368 715 701 75 297 286 628 607 178 451 469 346 20 527 331 447 565 683 602 39 503 394 180 241 399 346 223 652 599 128 594 298 369 738 549 744 666 733 41 106 190 508 260 336 447 314 580 329 331 378 147 18 314 238 491 265 599 114 619 95 583 509 468 392 579 309 414 748 677 366 398 570 209 61 312 165 399 735 518 356 131 7 13 578 735 599 258 540 111 48 732 196 716 120 548 457 246 54 183 575 231 10 119 484 435 46 648 416 565 651 420 44 47 477 396 113 19 718 396 692 178 28 585 622 162 66 705 421 308 31 156 321 678 370 535 461 428 210 628 53 662 256 223 350 230 445 489 151 204 727 450 592 590 175 266 556 190 612 116 730 704 193 522 330 432 318 669 568 615 342 654 247 3 517 38…
Output: NO

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.