CT48740

The Circular Route Beneath Duskwood

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Zane runs the cellar at the frontier camp of Duskwood. Today the books show a list of routes, and the numbers must be worked out before sundown. 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 <= 3122; 0 <= m <= 3122.

Example 1:

Input: 1732 616 1343 958 871 793 964 391 1637 1172 1416 822 297 959 20 1659 395 37 1117 239 1711 1644 1239 1679 156 726 1680 336 805 1231 78 719 218 1488 118 476 608 1349 1612 404 1582 1052 819 1120 752 321 1385 708 498 638 962 866 731 788 720 30 1076 1105 772 1715 698 1026 1637 621 1021 1455 756 723 1282 1489 623 1363 1593 218 950 1025 1088 53 124 1105 547 1083 1660 903 235 1557 1679 1324 773 1474 1064 544 1270 204 828 1533 437 397 454 639 1288 98 1510 633 1221 1266 858 1178 1684 1426 634 153 1392 1228 585 1691 57 118 67 318 1684 586 1180 969 819 1233 137 189 1462 846 161 178 452 720 584 320 1390 426 456 1031 1301 1435 723 1676 508 180 1338 786 1489 1684 711 1601 1332 1283 1017 1269 905 1707 696 345 1540 1031 275 1495 1412 1620 402 1599 1330 8 471 9 1591 1419 636 159 164 28 1719 697 1559 1529 42…
Output: NO

Example 2:

Input: 1166 3071 972 845 333 62 423 485 1110 1081 660 961 1151 580 166 47 82 741 96 1128 1160 696 676 674 1047 194 414 662 571 219 902 553 1032 160 462 718 142 265 632 387 1059 1116 363 543 769 532 349 169 631 827 481 432 956 202 600 1077 965 15 212 69 432 887 1144 1001 292 812 366 236 308 547 898 675 265 535 433 112 525 618 312 1018 37 905 142 1128 201 627 1155 240 596 416 61 745 638 280 701 213 697 801 937 11 807 414 25 694 817 220 729 574 996 658 815 279 1132 370 749 41 923 837 283 772 967 597 176 394 173 584 585 741 127 946 1060 758 754 377 143 137 825 922 24 355 936 798 957 328 737 786 261 717 577 1053 1140 875 23 309 868 99 759 713 290 608 446 586 172 893 10 702 556 397 88 1140 818 222 293 1081 1051 154 900 1098 443 1157 872 321 720 934 1025 320 487 124 127 170 380 925 726 751 96 727 141 99…
Output: YES

Example 3:

Input: 819 486 469 767 575 90 128 696 779 242 612 631 208 440 655 228 445 301 817 324 401 546 204 565 506 620 43 170 312 198 393 360 313 288 437 162 530 665 153 487 616 440 789 51 370 36 397 681 614 544 811 10 560 601 347 581 726 206 127 403 780 322 819 321 534 22 736 557 697 606 785 142 612 121 273 632 640 251 394 517 287 514 361 43 80 564 94 73 430 577 525 422 717 60 595 817 299 106 421 411 682 422 263 339 425 417 648 536 532 753 451 188 735 461 773 437 105 328 619 756 692 152 676 786 76 569 347 360 562 540 245 88 331 334 785 773 534 703 19 37 65 323 598 262 117 643 777 520 42 344 219 623 543 239 445 787 182 190 43 497 237 137 642 708 499 279 567 432 499 251 161 292 537 38 504 299 629 607 124 548 67 650 312 592 763 165 53 269 406 101 311 116 718 491 357 442 797 385 452 310 367 236 267 695 105 3…
Output: NO

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Circular Route Beneath Duskwood - MEDIUM Coding Problem | CodeTikki