CT54839

The Silent Circular Route

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Before the gates of the savanna camp of Amberplain close for winter, Pavel must finish the routes ledger - one figure at a time. 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 <= 3520; 0 <= m <= 3520.

Example 1:

Input: 2344 1902 86 1075 1563 648 1612 1802 1295 952 1736 1397 1730 29 2036 1757 1865 308 1450 1051 1510 2137 1070 2017 589 2188 874 1622 1174 206 1801 2183 1711 999 1520 2008 1303 780 40 346 1320 677 566 1048 62 2056 1544 2055 809 296 159 213 798 1125 1744 212 1705 1462 1237 542 954 1943 1290 1597 1046 1113 995 1544 2063 1154 2227 1147 990 680 443 1266 538 1954 1678 906 1400 163 183 1857 1684 357 584 1733 314 1602 2249 2049 910 495 267 101 1672 111 42 149 30 2 2307 2299 741 1371 563 1280 497 1037 689 946 2104 1806 1289 708 1887 1071 1816 837 1645 962 263 1623 1379 1876 1572 132 782 876 869 1736 832 1207 2216 479 1603 412 1967 2308 578 1978 285 46 1223 935 1645 2081 1067 1552 1672 299 1927 2004 1415 1628 290 468 597 5 94 42 1903 1710 1324 1239 807 198 69 988 715 603 916 73 77 518 62 2013 510 2303…
Output: YES

Example 2:

Input: 1834 2374 736 1387 1416 1155 509 1525 1138 375 286 1821 335 1559 928 1656 433 743 1640 1632 238 1321 1016 1740 399 49 827 1803 112 901 914 490 451 709 860 356 709 646 955 1388 998 997 1055 678 865 789 1002 11 1787 1809 937 932 1343 1421 1052 224 1202 71 1834 1629 63 525 1126 1794 830 552 1078 534 599 714 1239 236 594 1131 193 1093 616 848 1351 736 1128 768 1672 1289 1342 849 825 487 361 553 994 502 1241 732 1215 1522 1529 1420 850 480 759 1535 1347 1522 1436 718 168 278 723 1261 1337 470 1130 835 549 697 1797 432 808 1640 1217 647 1710 1309 154 701 666 639 1348 554 1211 1821 491 1616 1320 1267 192 649 1780 298 1557 33 724 747 1165 2 1545 122 1 522 274 282 702 1686 1117 121 1828 1091 1180 1721 1116 846 966 491 477 1359 1734 210 744 586 313 559 132 1689 135 1392 1627 1097 1667 1356 1187 1402…
Output: YES

Example 3:

Input: 2357 3507 1413 1397 1840 789 553 1383 1326 2352 1297 1693 1561 623 1687 1577 2243 612 368 1962 822 18 2080 2169 1935 2284 1412 2050 212 1290 382 2097 2052 2081 1447 405 2130 338 1733 1651 1356 1579 2263 439 1380 1231 985 1625 840 1567 990 1273 1499 1590 1814 1810 1444 1357 1140 920 2063 1908 1344 1493 184 2187 2266 1057 73 1028 828 533 1031 505 1421 1937 1668 167 2053 2090 281 2288 1281 506 1575 1829 1367 579 924 1666 11 1420 1260 1295 1832 1398 137 2020 1218 1196 577 2344 1259 2307 635 985 571 1977 591 2173 433 1335 429 234 1646 938 1680 1128 2299 1872 1372 1403 758 701 1471 347 679 852 89 1014 282 181 1430 16 203 1875 2072 785 1143 349 2302 1485 634 1822 2136 1157 50 1920 1388 481 285 1553 2207 2183 1121 1712 842 1367 1352 159 1702 1202 1246 899 196 2015 2131 870 2103 814 1822 331 1931 2…
Output: YES

Constraints:

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

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