CT39773

Rhys Counts the canals

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Rhys the ledger master watches over the lotus ponds of Tranquil Basin's stores of canals. A careful computation stands between order and chaos. 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 <= 3546; 0 <= m <= 3546.

Example 1:

Input: 2313 2728 38 349 1996 57 1919 227 873 1304 503 862 592 703 1029 1784 2229 154 569 149 1602 2309 112 2153 180 424 1263 1568 1332 1779 1197 883 156 1557 104 753 871 347 2258 580 625 949 1709 1586 1624 1071 2125 720 42 951 1472 1944 2311 1416 1654 480 1451 1736 331 486 1660 395 940 823 1091 556 1430 1482 89 127 732 1524 1183 822 1839 2030 883 1299 2251 1156 84 1747 451 1026 775 391 1461 1401 1487 708 1311 427 2251 315 606 935 1619 1247 698 192 433 1760 644 287 506 1840 580 1475 1379 1480 794 1239 984 1896 1607 208 734 1058 1680 341 932 2312 1426 904 1673 161 2123 56 1951 748 1536 2042 2208 1884 1122 606 540 991 744 797 1819 982 424 932 2087 364 125 611 1762 182 1103 37 627 299 395 613 1788 2186 2104 72 1149 18 1616 1379 1497 729 946 1789 93 1836 320 692 822 2161 2078 1821 307 2255 1415 742 56…
Output: YES

Example 2:

Input: 2170 2131 878 1429 1563 1928 841 1354 199 1123 348 151 1472 1417 501 716 1526 457 958 1279 1309 1857 1811 1316 2142 1168 1079 1731 2097 1517 1274 1893 1153 307 857 78 1698 423 996 1783 1186 2084 987 634 1641 1229 1462 319 1534 603 473 1586 1272 1255 1013 716 1376 424 1900 404 395 1173 905 1138 1247 2002 879 867 34 2133 1410 1754 1987 2021 930 1903 112 173 2068 1167 1537 791 1471 320 1118 1586 1726 1860 2067 468 2168 2000 2044 914 1430 1730 2105 1124 1067 244 1587 298 169 1883 337 723 1795 490 1472 1446 1637 1477 246 1732 209 88 2062 1563 329 896 1268 1736 2027 615 561 892 1576 1425 1300 1890 1744 513 1605 2092 491 807 1388 527 2066 1921 1091 1106 1015 375 1581 1723 256 2047 1888 1931 1041 110 32 154 362 869 295 912 822 1229 2158 1988 1445 38 587 1525 1427 334 2168 5 45 806 322 111 832 1297…
Output: NO

Example 3:

Input: 1457 3343 550 1321 627 1383 715 882 483 429 777 1131 964 843 1149 1070 779 1269 641 703 568 945 1387 766 454 300 1357 1200 653 647 124 1062 191 898 1305 55 1101 948 1092 678 1368 363 405 1192 14 1016 137 1362 1334 817 267 346 921 1023 992 1063 305 1167 699 1244 514 700 707 1309 1339 19 69 1030 1119 547 244 1030 1105 262 569 1361 185 142 312 135 102 455 340 1311 1335 356 102 20 356 1176 713 896 978 713 118 1177 885 877 1143 1059 74 348 416 1082 853 1270 1192 447 235 350 673 663 1372 357 1410 1015 466 976 137 383 935 1210 1152 914 589 658 128 1139 698 970 701 961 397 897 1426 437 1107 1269 399 1001 1220 1098 1398 1013 154 950 205 609 282 637 1343 181 1251 433 595 448 7 232 837 1146 685 1015 405 399 874 1279 1372 365 196 521 1178 506 1180 1079 1391 932 1262 954 1396 615 30 646 916 1388 335 52…
Output: YES

Constraints:

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

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