CT37423

Faye's Gilded Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

At the ferry landing of Crosswater, Faye records each tunnels 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 <= 2526; 0 <= m <= 2526.

Example 1:

Input: 2231 2247 804 41 636 1294 25 1567 117 470 1723 655 866 753 1278 1598 1678 1449 1106 1382 622 1918 47 579 2217 2208 1826 971 1135 437 892 1727 2231 656 1543 857 1531 948 1169 927 1839 1538 236 1669 2060 900 2021 1503 1011 1712 484 956 958 293 544 763 1796 260 22 223 980 209 1542 1064 8 1784 1854 1970 2030 1309 1957 691 87 1179 1621 2181 631 163 2183 1331 257 477 1195 1180 2026 887 1443 391 1433 1387 1877 2076 371 889 1723 2190 712 602 1900 1937 1770 639 482 667 286 385 1099 309 1714 1346 2072 791 1566 1748 559 1615 303 1868 70 1894 2191 51 1618 13 1481 2092 231 976 917 634 1645 524 764 2037 260 455 1938 852 315 745 1958 1184 1901 74 1765 1840 2085 1919 763 1490 596 687 731 1880 1728 1313 1167 1023 380 1016 1874 2145 1185 754 159 2149 2224 511 970 2196 2049 446 614 553 1789 824 1269 1382 12 …
Output: YES

Example 2:

Input: 796 1161 420 345 2 610 596 249 356 342 731 718 76 181 728 460 430 740 1 482 724 442 649 117 339 122 235 617 159 236 134 190 67 577 244 131 579 336 449 26 297 742 463 182 732 189 782 129 364 520 211 201 347 680 689 780 378 476 492 134 44 61 151 356 3 240 138 269 478 494 425 742 16 391 515 699 497 145 201 565 53 372 270 101 413 737 174 457 297 186 110 642 474 645 717 561 385 225 275 510 578 203 424 565 575 783 547 224 8 628 218 23 450 421 721 728 277 110 557 671 630 124 514 468 100 581 195 495 743 200 316 428 624 155 389 509 512 784 488 660 1 181 321 186 11 700 195 271 652 604 232 600 547 440 263 760 617 551 25 581 565 90 618 108 262 216 748 613 468 37 19 634 77 485 309 244 158 697 22 158 346 676 591 327 650 746 68 607 404 491 284 42 231 298 794 211 493 211 29 62 329 550 411 557 606 787 525 …
Output: YES

Example 3:

Input: 913 1805 256 339 379 452 350 857 108 309 473 796 427 869 598 477 332 82 194 714 883 123 183 480 268 562 148 774 620 199 909 544 571 105 819 185 502 52 446 90 631 817 28 184 100 344 615 490 433 816 765 804 297 751 604 227 626 688 395 872 832 229 833 422 434 901 350 441 629 802 140 780 188 525 782 909 642 680 706 808 279 242 54 437 609 430 94 637 261 709 561 778 101 649 622 445 80 553 698 775 427 522 684 16 226 251 360 592 395 555 456 834 458 741 506 376 161 691 356 639 542 703 311 714 681 650 199 835 45 913 492 415 735 743 509 373 130 801 241 322 87 3 226 311 247 722 349 123 766 217 176 839 189 416 115 31 202 752 840 583 742 147 605 198 311 831 497 842 124 183 97 508 617 578 776 849 302 106 345 227 768 112 731 648 272 561 13 823 743 339 761 889 860 870 661 818 414 259 909 14 308 626 847 790…
Output: YES

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Faye's Gilded Ledger - MEDIUM Coding Problem | CodeTikki