CT46936

Hans's Circular Route Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Every season at the gull cliffs of Screech Point, someone must prove the quality of the harvest. This year the task falls to Hans, armed only with the tunnels register. 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 <= 1956; 0 <= m <= 1956.

Example 1:

Input: 1646 980 829 194 1416 1177 994 652 1410 980 1395 979 1582 1283 1615 802 1371 466 911 1252 290 740 358 1243 196 158 345 1430 365 182 378 200 444 1083 305 591 159 177 1127 1567 1059 1394 1044 1579 755 367 395 3 627 102 1598 706 1394 671 761 935 1284 1011 124 1154 1081 1336 994 121 120 1121 536 381 162 1453 1482 153 159 1513 1068 58 874 1055 1073 436 685 132 490 1634 170 1106 273 829 527 331 588 1387 1547 522 656 870 1287 1442 538 221 1064 560 250 829 1436 1514 364 1640 1333 496 264 586 1611 1489 1371 1143 189 168 625 883 1481 5 735 618 1128 16 298 614 1276 1641 945 1073 179 1172 1642 1610 1597 1255 555 583 725 1577 175 107 371 412 311 343 614 204 1490 715 1573 406 1245 1205 247 720 1230 212 92 921 25 66 647 439 642 1305 30 1563 1463 1431 571 30 826 434 77 1187 721 640 478 1247 804 1603 213 4…
Output: YES

Example 2:

Input: 1909 404 1050 370 432 1842 894 1746 1888 363 763 986 1454 1172 1627 39 473 1624 117 1009 486 138 1046 350 1223 513 1711 1845 811 248 817 238 1756 1900 531 652 695 1718 959 871 1609 193 1579 1122 368 93 214 432 940 924 1026 1441 491 45 559 869 1357 442 195 1068 941 1012 1088 440 1210 1760 773 705 761 42 574 459 459 1054 1141 1665 443 1694 1691 1820 921 883 537 541 449 994 809 489 1765 286 1274 718 1103 1448 1748 1702 1817 558 1047 1246 1559 1357 262 677 1403 412 788 1146 213 1603 889 166 1195 1871 1174 1794 621 1539 1170 1251 1792 1255 112 198 1180 978 1493 458 160 926 1848 1357 160 432 711 337 702 615 1506 1234 1773 108 757 1607 825 928 167 1729 665 642 30 1472 1087 998 631 1293 1402 273 149 42 1388 668 1877 1302 491 824 1629 1651 1196 281 923 1160 1865 614 1832 247 763 1216 776 1492 1318 …
Output: NO

Example 3:

Input: 1435 1946 202 1183 117 791 556 40 570 1399 595 844 161 563 779 375 111 1191 1007 1127 795 1268 730 492 339 141 929 1432 472 513 302 842 1117 1424 1313 1154 58 166 999 572 110 333 118 311 872 842 751 86 607 132 1131 247 180 62 241 183 689 1065 509 574 1099 752 1023 1430 1092 32 559 363 56 842 599 534 1159 501 438 1348 163 13 948 772 1067 559 91 1029 931 376 878 276 513 250 896 1095 1351 361 917 1383 109 520 435 1421 510 864 853 730 1339 1011 1005 418 52 336 593 1226 71 242 1180 1413 98 149 1342 935 777 1377 1335 767 1231 1096 1171 874 538 1424 660 13 866 581 251 154 77 852 1195 1281 481 679 1366 91 580 450 360 945 591 1243 490 834 236 892 871 1000 33 1391 964 791 993 588 156 231 195 981 861 1134 1365 34 1177 777 166 671 442 955 119 1121 82 375 1254 280 1396 591 1343 55 1366 1378 594 1004 79…
Output: YES

Constraints:

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

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