CT38288

Chandler's Umber Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

It is audit day at the anvil district of Hammerfall. Chandler spreads the tunnels records across the table and picks up a sharp pencil. 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 <= 3266; 0 <= m <= 3266.

Example 1:

Input: 3180 967 336 3017 1620 1111 856 708 1227 2509 1796 103 341 1097 2420 740 3143 753 2775 2163 502 2639 880 2304 2488 2875 1502 2630 2512 2849 2813 1352 1862 808 989 2827 2937 101 633 3071 2721 2420 1572 1582 2436 2744 546 411 2218 730 324 751 517 1158 943 146 1531 2903 1914 70 1546 2487 2930 1113 1200 2022 1643 1933 1920 7 2109 1418 2046 205 1573 104 881 1753 319 1603 872 1813 539 2561 858 2775 300 322 1003 1700 840 102 1778 1178 2934 2437 1584 1164 1019 1256 2456 456 1208 2456 543 1075 1611 582 2322 1622 726 2284 3063 1130 2043 1448 578 1065 569 625 2818 347 2977 83 2276 2562 953 1127 1605 925 1031 1282 2719 1396 1117 1892 169 504 236 2367 2029 2172 233 3027 1369 644 1813 814 415 743 2364 9 495 658 1790 1159 1741 2599 2743 1551 2698 1828 837 2135 2654 2366 2456 841 1258 1138 2207 1309 2753 …
Output: NO

Example 2:

Input: 2564 1230 1325 1060 519 2564 2149 1604 2387 858 1201 412 1236 1033 33 1156 2129 263 966 1484 1949 1889 2414 591 1681 1589 238 2222 1353 1356 403 2273 1426 2158 2372 1054 2554 1389 1041 1317 1491 1139 2546 403 1776 2492 1547 376 624 244 1649 1992 231 2097 771 900 1894 378 2042 510 630 1873 197 1400 858 2527 1971 593 1803 2409 305 1155 485 2122 1262 2255 354 1522 2545 1258 389 1389 2512 1232 1145 788 2178 107 149 443 1462 2035 656 2073 1036 2132 851 1181 564 1466 505 1661 1879 455 2462 1911 2557 2180 1150 1934 103 321 2443 1918 1238 254 1831 1659 1580 498 616 1021 913 863 446 1499 1229 264 2068 1320 2494 1255 442 1359 453 884 1422 841 278 1798 1453 1843 1702 98 1229 311 1237 822 1538 1001 2416 250 1798 700 1103 2435 2400 1680 1973 1345 405 1447 195 299 1904 490 1310 1904 1677 2307 27 1066 62…
Output: YES

Example 3:

Input: 3221 2521 1367 1989 2769 3209 188 2511 230 2840 1783 2603 1684 2965 103 474 2550 1175 2967 2654 2949 2447 1060 2226 1587 1744 1798 327 737 847 2689 2612 1903 1478 2110 249 136 1067 1350 124 171 2049 1687 1349 2240 2668 2330 350 726 3165 1067 1149 1610 500 882 2427 2938 3211 1868 1794 2384 3020 2814 2574 2645 2981 1838 1760 735 3171 1001 214 1947 1164 159 3032 47 2430 176 2049 3011 113 2894 1761 134 654 2838 5 472 1909 1025 2489 1502 1728 1983 1364 758 688 2175 552 2118 1927 1951 675 1695 1912 1847 1474 17 1329 1919 75 335 2218 84 2998 82 652 2759 31 1262 3209 552 1139 2192 751 122 437 3173 1911 1723 536 455 74 2384 501 361 45 2726 1264 1565 2551 2187 1230 1591 1328 460 407 23 2027 2804 513 734 1471 353 1515 1483 333 662 2729 203 2108 1728 1707 2499 1220 538 1678 711 964 33 1440 13 1009 676…
Output: NO

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Chandler's Umber Ledger - MEDIUM Coding Problem | CodeTikki