CT56324

Brewer and the Zigzag canals

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Before the gates of the maple sugarbush of Saprun close for winter, Brewer must finish the canals ledger - one figure at a time. 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 <= 2215; 0 <= m <= 2215.

Example 1:

Input: 1959 1816 1238 85 1194 1628 445 210 1498 1121 1879 1359 126 1864 1422 1148 866 448 285 1536 961 1077 1242 676 617 751 1041 879 1854 1214 1097 408 304 961 1248 831 1462 236 1450 762 1136 1638 1043 59 1743 152 1491 1212 318 742 986 1525 224 234 275 27 1220 500 1743 349 190 1586 646 9 1544 908 1827 357 1312 1596 589 15 757 1926 600 1852 575 889 1381 1511 177 1889 487 1634 1276 1221 664 454 1516 838 1669 1145 1499 275 1759 1072 621 1336 496 1172 87 1449 1430 835 1168 248 1211 1901 691 1240 21 179 1711 606 204 607 793 1035 1897 9 504 405 532 54 130 1670 87 1910 677 176 1218 268 1660 1798 966 1496 1314 1099 524 1222 107 1203 1761 242 1890 1250 739 97 1733 1078 31 288 629 837 271 436 1183 1934 1946 441 6 757 1636 578 1242 103 1630 830 1497 1762 1069 281 7 1287 223 466 1854 900 946 356 272 1945 15…
Output: NO

Example 2:

Input: 1158 799 733 357 323 764 107 242 822 84 613 516 1018 981 185 645 851 502 935 135 1157 802 1117 789 839 275 535 986 1019 1023 362 47 1055 664 328 181 193 270 1081 761 447 539 538 1158 551 565 605 9 375 899 169 752 1009 462 25 1054 994 904 9 1062 324 387 400 1011 816 134 560 127 647 258 180 972 177 504 219 41 1031 205 541 310 299 1138 750 221 728 738 539 234 1077 311 860 640 566 48 484 365 333 847 249 450 809 578 674 813 782 826 731 298 206 147 210 570 958 460 241 990 41 43 623 300 626 642 141 152 945 338 193 532 288 754 1057 675 5 840 734 133 159 688 575 1134 44 938 329 14 1026 16 781 798 970 1082 133 546 951 640 620 508 221 88 741 416 868 13 372 1076 76 583 856 343 519 531 348 508 4 371 1074 1119 149 559 768 1157 1051 90 903 472 47 163 847 461 589 408 370 850 150 559 1138 1047 267 1017 100…
Output: YES

Example 3:

Input: 946 1169 824 767 442 677 22 360 685 146 138 68 799 802 91 939 746 165 54 272 665 761 230 124 906 648 797 16 428 283 563 782 924 593 287 343 514 202 817 614 696 159 86 693 858 4 839 599 46 326 333 527 74 923 584 166 344 273 410 842 443 86 564 558 689 596 840 522 230 690 586 705 393 351 681 459 895 534 110 247 932 945 142 751 525 587 868 885 307 45 501 229 367 549 886 546 341 136 473 383 928 421 440 580 813 168 808 476 906 746 557 575 320 319 738 571 881 210 572 227 420 7 111 4 667 218 374 572 202 746 358 153 441 811 425 323 111 488 67 657 225 45 151 101 587 946 615 532 903 109 279 205 629 194 704 454 603 172 754 8 893 9 841 40 500 817 244 552 780 388 937 412 739 472 920 758 652 251 379 479 140 191 93 347 807 791 238 684 638 510 563 81 801 913 199 102 944 438 410 535 437 933 583 874 860 270 …
Output: YES

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Brewer and the Zigzag canals - MEDIUM Coding Problem | CodeTikki