CT50956

Whispering roads Circular Route

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

At the cliffside roost of Stormrest, Yami records each roads in a worn leather ledger. The guild wants answers, not guesses. 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 <= 2924; 0 <= m <= 2924.

Example 1:

Input: 1977 491 1335 1173 1726 1237 1680 1977 582 1790 496 499 1176 1641 1909 631 1055 734 80 1683 653 393 1345 1962 337 1966 896 693 480 1366 938 1551 221 1212 551 1628 1483 1401 793 490 1094 47 754 1159 1207 127 485 249 1645 347 1542 897 1879 878 216 309 875 1180 1790 346 1381 885 882 644 951 1592 1084 1621 1000 1595 1654 1185 1348 746 811 1836 106 1726 1607 675 1156 1517 269 1223 1884 1937 1376 197 383 1224 1180 1188 1740 970 1082 1716 1229 846 1747 207 1938 544 1749 1408 762 1864 1535 252 1304 1566 1317 267 1074 709 1129 467 561 30 534 1026 282 439 541 289 1432 329 1047 1325 529 1220 1316 462 1362 1111 1862 329 1042 920 236 1198 47 625 1919 569 1550 1286 1292 292 1032 255 881 580 1691 1687 710 334 1042 1875 277 321 307 428 779 252 511 158 1776 649 962 1847 667 329 1131 1190 891 1319 1879 421 …
Output: NO

Example 2:

Input: 1928 1388 696 96 1894 41 1129 719 189 1486 848 429 1614 1385 998 1390 1921 1544 55 1061 51 1632 1030 1101 225 944 267 942 581 1612 360 363 1365 1025 367 817 1270 1032 864 1451 195 381 1000 851 1657 1302 1335 783 1031 686 973 1765 355 1363 979 1064 4 975 124 509 1001 1468 610 659 1234 1893 702 469 645 1194 373 1179 118 1541 1132 989 390 1556 1844 858 310 1254 44 1450 1096 1904 1812 1092 166 1192 1170 309 1866 611 42 1142 1474 1221 467 575 1282 1216 1144 1185 1653 1819 1468 1824 96 1768 221 987 395 300 137 1693 422 54 906 849 1222 1867 182 1276 846 1380 1655 80 663 323 1915 1201 1060 681 1177 1154 554 1316 1671 163 840 799 221 554 1401 322 680 1348 178 1012 1630 217 29 83 1750 1263 406 400 1568 427 459 257 353 932 923 312 974 1215 9 777 1083 899 1509 1824 1386 1864 1273 236 188 1334 1507 165…
Output: NO

Example 3:

Input: 2275 556 639 1237 1882 1840 1544 700 1859 1220 1911 753 167 1402 159 280 69 119 1664 1289 2103 746 1527 2074 432 1122 1808 1383 1013 35 1824 646 2215 1498 752 481 2023 58 1458 670 1457 1490 286 1630 1274 884 1113 1361 964 1447 186 1526 2035 275 247 1017 1769 210 1397 1247 881 2205 2112 328 1701 1925 872 168 199 1533 740 240 1598 1947 1774 415 1112 1129 2220 1725 1983 2178 1551 55 1175 1328 195 962 1699 1230 1754 547 787 1744 2183 925 202 2012 1544 542 1102 1275 1900 7 851 951 1895 1852 1738 1607 2258 1369 92 1097 418 315 2080 1496 1674 941 946 652 2125 669 22 1620 1527 1299 32 953 706 1620 1078 1224 1173 1221 2042 1281 680 1895 2092 485 695 815 1132 123 1931 655 1514 1007 150 1114 658 1526 1798 1101 1448 1975 1100 1773 642 458 1685 372 1666 680 1898 542 860 416 475 236 1130 448 1618 792 61…
Output: NO

Constraints:

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

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