CT43102

Rohan Counts the roads

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Morning light hits the canyon post of Redrock as Rohan unrolls the day's manifest of roads. The tally will decide the next shipment. 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 <= 3954; 0 <= m <= 3954.

Example 1:

Input: 3495 710 2104 2442 1895 2117 3035 1795 2008 163 919 561 2135 3199 1752 2430 1451 3186 297 2895 859 1253 2277 890 3250 1878 27 1998 2990 1149 2105 376 1904 1512 1144 151 797 1173 485 2939 3177 25 2084 375 2984 801 914 3034 2907 300 617 1265 119 2642 1272 2334 3223 2806 2331 2067 2635 65 3168 1853 3045 293 3286 2835 1914 552 2886 179 251 2674 3336 3112 1718 460 3025 3319 3427 2941 1399 1448 3294 2605 1090 2956 2674 1826 2357 2364 285 1057 2473 486 2403 2181 2733 407 643 1862 3320 415 2002 3015 828 2103 3443 2985 160 150 2082 793 3373 544 980 3477 2947 1622 102 1741 3056 1663 2537 3052 2580 564 631 1681 2440 2688 482 1973 1391 3168 1591 1126 2152 2712 552 399 587 3005 1673 2911 2527 622 2676 2743 3258 1920 1796 1000 3266 1908 1481 2078 2115 2827 1618 544 2535 2458 923 2522 2389 1640 2608 2557…
Output: NO

Example 2:

Input: 1181 464 933 608 185 313 771 816 493 909 352 852 31 513 592 1056 46 667 553 248 862 526 891 942 683 1176 1091 97 165 430 1149 461 9 1167 675 932 1015 12 1146 393 1153 74 1050 969 495 59 477 707 1046 1120 1162 1035 680 1045 568 374 207 410 286 889 507 1175 727 764 509 1042 597 848 1109 411 845 230 43 425 893 41 1108 1044 927 140 3 559 352 871 109 867 1150 555 904 451 562 339 461 430 348 500 643 778 841 931 697 345 138 609 625 322 437 470 961 411 815 370 437 546 392 464 263 488 853 1174 908 109 1053 324 883 1034 840 555 759 699 1036 217 172 847 195 405 998 1144 1102 31 531 838 89 712 352 79 167 865 790 7 992 881 587 767 634 1029 547 523 586 985 417 182 493 329 553 999 541 1100 89 804 521 99 1015 64 109 575 732 6 749 463 303 209 776 320 764 1166 1161 315 510 1027 934 187 863 726 376 752 632 1…
Output: NO

Example 3:

Input: 2425 526 570 368 280 376 2349 2386 728 895 434 2126 1454 634 1204 876 1369 582 1220 448 162 2312 2300 22 370 482 1328 1509 336 276 1033 2110 1474 2216 1137 2323 1474 1876 1636 2384 581 866 753 1366 1957 803 1891 1757 2124 633 695 2264 956 907 51 768 320 535 425 1928 471 350 2113 692 2260 233 1411 1026 397 950 393 1471 1463 2322 2353 730 619 1606 395 2254 2059 1660 2369 937 547 1446 2348 249 2240 360 2180 1323 1002 241 1033 677 844 1166 71 339 999 824 1863 352 655 1711 1725 1349 2264 1331 83 1210 1204 2187 118 1698 892 1472 2003 1838 1627 102 1542 1062 520 1913 2408 2401 1212 1907 2080 1046 741 1686 1818 1558 693 603 1339 2252 610 1451 1813 1886 937 729 1602 206 1262 1327 1922 1043 1118 923 383 1092 1102 1346 584 534 1017 148 1033 1362 1230 1795 2023 2417 7 1713 1029 1921 659 67 1708 59 218…
Output: NO

Constraints:

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

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