CT40633

The Stonehallow Circular Route

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Jeweler runs the stall at the granite steps of Stonehallow. 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 <= 2824; 0 <= m <= 2824.

Example 1:

Input: 956 1937 224 868 633 548 110 224 560 785 70 792 239 680 492 271 955 195 798 546 329 930 606 359 602 19 862 837 693 635 328 464 603 517 744 701 698 13 117 552 666 337 391 38 385 209 880 47 23 801 307 425 881 564 197 914 516 38 524 602 512 523 655 291 308 66 563 538 611 138 253 416 563 170 31 611 400 893 532 299 605 340 601 850 3 553 236 77 643 269 362 60 203 822 681 510 895 269 356 257 640 115 895 752 106 848 585 127 369 942 110 440 399 228 138 783 702 305 393 237 283 717 692 40 212 5 595 157 852 424 284 723 686 182 590 548 586 526 146 730 888 917 145 444 673 916 535 828 686 253 449 57 443 103 421 127 278 66 23 400 424 654 543 880 848 668 522 768 540 597 844 874 716 585 244 93 896 96 556 107 665 653 354 598 372 608 634 201 127 437 517 28 898 246 643 66 575 487 545 838 867 686 845 639 392 20…
Output: YES

Example 2:

Input: 1205 1787 589 396 1059 921 240 287 477 414 603 305 560 127 573 389 726 227 1172 413 882 208 247 1034 997 142 793 967 278 1044 1167 771 887 1146 1146 909 1002 1167 1109 1038 1032 1026 51 53 773 460 452 832 341 1159 146 8 49 695 436 586 909 542 591 694 402 5 315 976 833 1110 461 1068 208 732 269 862 643 240 117 969 768 717 36 750 830 749 668 547 484 1205 817 102 804 920 460 702 372 840 789 555 1200 875 1002 550 337 974 1142 142 666 151 1068 168 956 1052 1170 113 1143 932 527 1031 1179 930 986 691 873 147 899 793 710 494 1203 312 1194 254 739 347 816 988 794 966 1153 518 315 729 512 647 929 265 226 39 1154 300 502 1023 543 798 1028 173 1077 1151 644 832 519 349 936 259 521 329 706 1024 167 65 467 162 45 1163 83 866 540 154 557 773 872 658 185 672 915 967 1164 39 32 336 667 436 668 742 896 106…
Output: YES

Example 3:

Input: 2773 1283 2755 449 2772 1732 1109 1121 671 2228 1033 706 1908 2207 424 801 558 1784 127 1930 2225 2023 1612 171 1059 516 1154 564 2518 1802 334 654 43 1442 1027 2234 1046 1787 1149 1818 1358 2592 2584 946 1134 334 1248 78 2642 1589 724 2518 71 791 1200 555 2746 1130 899 1850 1544 850 58 1477 2093 884 2046 2741 1382 2681 2208 404 2596 25 1388 1469 36 2069 2636 1027 1410 1191 995 176 316 1631 2514 1661 1677 530 964 1054 795 860 1611 1552 2122 149 396 585 1536 157 67 2324 1674 580 143 1727 854 2466 774 773 1221 2506 2190 1634 1065 2772 1678 1863 580 1018 2569 520 1921 1204 1514 54 731 1012 1148 807 40 1722 210 1728 1719 1637 249 911 1478 426 1221 1787 610 57 2447 1260 1745 1474 250 473 712 543 42 1923 2264 2540 1683 2386 2488 1787 266 2381 2744 664 1008 2475 2568 2562 1846 896 1374 798 605 72…
Output: NO

Constraints:

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

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