CT36926

Last canals of Felix

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Legend says the vault under the coastal hub of Tidewater opens only for a perfect tally of canals. Felix 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 <= 2245; 0 <= m <= 2245.

Example 1:

Input: 852 1463 741 17 84 95 523 45 349 777 304 100 479 723 238 832 820 327 143 14 830 342 251 115 360 670 267 499 301 660 156 449 72 760 803 79 459 76 837 690 566 24 125 246 587 752 458 535 486 529 341 791 686 776 274 592 423 207 845 445 696 105 174 298 520 146 517 280 475 233 502 780 379 586 649 109 605 535 162 710 462 302 89 660 415 80 612 439 413 841 815 415 331 699 783 43 584 548 293 675 151 726 839 562 783 257 618 408 689 258 82 809 512 625 285 336 712 517 619 94 831 246 546 390 641 114 680 720 670 660 100 124 39 234 576 644 586 787 761 121 669 94 177 299 748 665 118 800 448 595 192 437 656 521 66 814 348 181 343 850 56 797 838 671 837 810 154 365 272 448 787 266 632 397 597 618 198 183 607 202 611 284 69 339 8 23 752 836 471 748 617 16 273 88 421 161 827 313 195 2 389 842 246 122 238 243 7…
Output: YES

Example 2:

Input: 1220 1731 896 510 832 132 760 742 873 547 756 565 103 148 593 784 1214 251 656 55 666 733 430 1200 612 454 694 1076 420 215 944 160 920 760 192 135 1085 1044 768 1030 502 231 113 838 315 953 389 145 346 743 355 279 1070 1121 654 410 87 210 1055 832 792 236 487 1002 368 457 576 931 135 1084 186 943 112 670 51 481 633 209 623 10 814 567 977 599 1163 704 666 1024 102 1151 1185 1127 842 267 49 528 932 897 576 797 129 710 1095 408 793 316 4 841 447 395 542 897 197 592 1080 545 741 159 596 1172 321 1201 319 996 205 325 1004 1002 788 195 306 640 40 238 229 250 763 36 526 564 610 419 664 739 154 1142 231 705 1170 36 592 837 1062 643 793 391 633 913 123 1215 208 977 428 17 933 123 923 275 1016 961 1097 247 348 1051 576 859 567 720 821 1212 908 904 48 187 778 429 1141 179 299 1025 413 104 1173 1196 …
Output: YES

Example 3:

Input: 1843 1694 473 1325 1699 1216 1128 1506 1528 241 754 455 1151 1450 517 73 1134 1531 1222 546 562 1086 1720 1555 397 911 1323 1043 300 1228 572 1077 852 681 995 1000 1501 798 1610 96 967 491 50 43 1565 978 1610 127 1198 190 62 350 158 1298 1380 316 1292 1749 328 688 1144 1097 1481 1590 542 418 251 1368 1367 85 674 997 1481 1651 1360 515 835 973 1669 1494 248 1041 858 33 423 970 1449 29 1400 1028 1068 1527 807 545 1489 329 1642 500 1687 657 1446 1053 796 522 322 1832 1581 1464 41 1327 673 680 733 1550 1227 1236 881 128 103 1015 1071 522 631 1004 951 1808 1250 1535 1739 1324 411 184 1574 1000 509 834 140 1009 1756 1035 338 558 1280 1754 458 483 488 64 576 1380 412 1258 724 382 1331 208 1187 877 1592 1422 618 439 676 766 1732 935 1404 1703 1313 1728 1232 1502 1040 89 782 1404 1027 1829 1584 625…
Output: YES

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Last canals of Felix - MEDIUM Coding Problem | CodeTikki