CT38975

Vigo's Golden Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Legend says the vault under the tundra station of Whitesnow opens only for a perfect tally of canals. Vigo means to find out. 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 <= 2574; 0 <= m <= 2574.

Example 1:

Input: 736 737 55 482 720 601 472 286 174 642 707 106 368 25 478 242 286 363 403 719 699 558 570 597 544 422 409 653 418 136 545 38 183 450 675 466 727 357 68 314 633 596 140 314 466 625 466 530 23 2 454 364 670 560 594 388 259 653 499 497 375 196 72 345 398 360 629 341 266 617 680 406 259 622 693 189 477 567 277 629 445 50 370 676 416 601 610 203 32 443 324 446 631 627 63 129 261 13 352 446 249 321 693 84 601 6 346 368 328 276 122 79 57 498 331 8 276 191 120 18 580 534 532 249 654 425 248 138 55 562 614 477 615 567 304 410 92 559 6 414 302 303 289 6 572 719 200 413 489 497 94 713 486 157 192 266 316 385 661 87 585 99 650 14 117 619 538 79 671 558 733 726 626 502 539 415 725 71 252 512 275 500 723 205 686 542 347 662 39 559 221 676 135 360 435 164 426 94 50 239 40 70 467 346 123 415 337 504 29 61…
Output: YES

Example 2:

Input: 2087 1747 640 175 1060 668 145 377 1750 955 276 186 1206 266 977 1984 701 277 1793 1491 1581 673 1919 1752 108 1477 1094 1208 1891 445 1092 1360 376 1382 2047 1923 187 1324 626 1224 1197 190 1748 493 1564 393 685 1593 1675 1279 1935 1191 1343 96 136 1700 1864 1754 334 1949 1106 168 447 1956 327 1975 394 1021 133 1700 1109 81 873 693 1893 412 801 21 1826 24 1817 1739 1403 1688 928 1253 426 1841 728 1178 113 1475 26 1452 15 982 1513 858 998 1535 1275 342 1738 1057 1080 494 985 168 1480 294 107 485 818 2039 882 1401 1257 60 413 234 721 1633 1454 300 2050 1837 1182 807 1328 583 957 1244 984 1609 1319 301 1478 1127 819 834 1252 562 2013 993 1412 1264 1720 921 912 777 61 1187 445 488 1119 1345 989 1641 339 206 2057 1908 1899 1463 1788 1489 787 1107 473 1694 535 1813 900 1643 1296 1405 385 2056 1…
Output: NO

Example 3:

Input: 2124 1988 209 1420 227 1140 1228 2020 79 726 785 360 1979 72 951 1175 240 2071 416 140 199 337 29 779 843 459 2123 1104 1004 886 2051 484 2016 1526 928 864 278 1045 1058 1245 1157 224 1458 157 209 1206 1470 310 1026 1998 121 906 1811 1055 850 352 704 391 775 1226 505 1000 1726 1798 394 883 971 1284 1895 1969 640 1129 697 1726 509 273 714 1741 2010 1972 903 1303 1138 1801 1266 1151 446 1463 1460 1607 1901 1172 1649 1277 1267 1522 2024 683 1106 557 824 856 1619 1903 660 755 1090 2016 1426 1159 1099 931 1153 1718 1927 1554 1267 45 1143 690 1278 1453 140 1515 1787 1102 1771 471 968 207 1236 1235 1562 440 16 747 957 150 557 1558 592 703 1718 358 1547 1928 2088 697 1579 1544 511 16 1159 541 762 1855 267 365 358 1586 1497 448 649 866 408 1623 430 809 332 2042 1924 684 1078 1776 970 1911 1431 1575…
Output: YES

Constraints:

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

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