CT47753

Morgana's Circular Route Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The harbor bell rings at the bamboo terraces of Verdantstep; Morgana weighs the day's canals manifests and starts the calculations. 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 <= 3021; 0 <= m <= 3021.

Example 1:

Input: 1986 788 1545 852 643 75 748 697 870 475 231 7 243 989 668 865 1846 1892 311 1739 494 1119 893 237 1535 1367 1847 1228 300 1174 1601 1945 876 670 590 1974 134 1450 1007 156 1552 1195 1665 1186 1537 362 1537 1174 1669 134 438 815 1727 424 1379 75 233 211 1744 133 88 972 143 281 1942 1793 1550 1406 77 534 1597 99 599 1154 1128 515 1984 44 887 485 1892 745 491 1314 1585 1223 16 1417 653 369 1013 1944 121 484 425 383 39 984 565 1528 1890 544 526 1587 1470 561 1022 478 279 1873 1527 1751 1465 1627 918 480 656 1289 1528 1355 1961 887 168 1703 737 249 191 905 879 841 1775 354 1799 215 1639 1618 1688 362 1458 663 1159 38 267 1015 260 297 109 1677 1460 844 1812 56 911 542 823 532 319 1864 1443 1151 851 691 773 94 1920 1347 122 1739 1694 994 1462 1343 303 620 1325 633 1761 460 71 1938 547 1720 1270 …
Output: NO

Example 2:

Input: 2394 1849 1952 1274 83 611 1208 1290 999 206 1165 1583 2374 194 2287 214 737 748 1495 76 625 483 684 1033 1747 321 538 807 1393 1682 421 1654 1421 1237 265 310 1158 1483 2 2221 1051 1369 1642 2227 1656 2301 1778 1349 2311 2305 2138 648 25 507 1152 230 546 2077 155 1831 207 1567 1827 278 420 369 311 1641 1243 866 1578 718 306 1279 674 117 640 190 721 2124 1329 1129 796 2205 2079 1432 1569 245 180 928 696 1381 385 192 2069 29 2207 1850 1148 1331 2366 2384 2214 849 189 799 633 1453 608 835 868 1021 587 1130 75 993 1646 17 1299 1434 1694 1292 1229 630 630 2153 1491 1839 366 53 2163 1830 2163 1647 204 1297 1606 1523 655 14 971 886 240 1028 534 2284 665 697 1947 1289 932 2126 2363 1336 1868 717 1458 1537 542 828 2095 548 114 832 1688 1026 1667 1149 415 247 2025 628 1801 1375 1562 1048 113 90 237…
Output: NO

Example 3:

Input: 1470 29 705 152 66 1457 919 1404 862 674 1034 406 517 148 1156 750 641 437 1135 936 964 1275 356 158 300 947 828 1000 521 1395 931 1294 724 347 900 152 798 414 148 894 598 143 1119 64 503 327 1371 909 1023 834 1204 1468 972 836 1294 117 1117 779 1052 672
Output: NO

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Morgana's Circular Route Ledger - MEDIUM Coding Problem | CodeTikki