CT47847

Tarun and the Sunlit canals

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Before the gates of the copper works of Verdigris close for winter, Tarun 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 <= 2773; 0 <= m <= 2773.

Example 1:

Input: 1235 1572 556 640 841 586 516 34 550 913 302 164 683 892 1019 458 960 756 662 726 132 342 1110 604 532 787 559 1092 954 878 922 478 327 135 513 61 711 433 547 1018 879 631 536 620 1169 602 24 1038 332 506 265 9 70 395 219 672 12 367 1072 276 641 1178 948 580 1141 834 200 237 306 276 1153 721 521 865 812 666 933 460 81 92 915 56 1134 229 953 252 228 638 1042 1074 976 973 972 969 1095 161 192 28 556 862 69 83 779 75 1135 1172 477 1017 452 602 836 1231 447 702 1214 280 248 13 1023 421 45 147 554 992 74 688 1142 876 868 799 396 736 763 191 394 979 1103 245 1026 677 338 193 470 201 429 160 998 90 927 955 175 638 1227 241 34 99 1173 263 1041 1111 454 638 659 674 29 773 172 258 324 1069 264 408 681 1114 732 210 299 135 1104 628 528 1028 598 182 664 931 337 1063 392 319 1079 1125 437 1225 664 203 …
Output: YES

Example 2:

Input: 2654 1342 111 166 679 1479 393 2121 2567 337 2431 2242 2510 260 601 947 2348 1903 407 817 7 620 1992 1306 1407 1559 1581 227 1408 277 666 166 68 1671 1657 1336 793 1509 113 843 1195 1787 1388 1869 371 212 2425 1933 146 1680 2032 2447 1160 99 1109 1391 1444 71 20 2125 1253 408 1575 1643 1419 1767 1245 1867 922 82 1221 977 698 2586 1648 355 222 26 1432 1531 1923 818 152 2183 1652 2 1815 2016 2225 1936 2051 1287 2519 379 1408 275 1375 2512 107 1477 433 2214 2130 315 1226 863 2550 2290 2372 219 2332 2036 1291 1631 696 2524 2454 1656 1031 2211 138 2375 2388 584 1897 705 394 788 1970 1145 2642 2312 1297 1781 1809 1803 388 2543 1845 2439 1059 2 441 678 2110 1536 125 553 1473 751 1712 1055 2379 2178 334 1251 47 1486 1565 493 1726 1433 420 1785 949 221 2527 899 1749 1504 1689 756 2571 2363 915 1576…
Output: YES

Example 3:

Input: 835 584 666 787 634 471 645 86 475 694 206 131 232 650 116 77 448 624 543 302 402 240 579 392 573 650 419 2 688 689 383 68 170 579 604 9 224 13 188 489 613 441 713 520 305 306 576 443 769 177 210 789 818 592 329 356 427 746 635 448 232 488 109 648 751 831 244 254 491 21 755 399 184 279 68 225 770 107 551 358 420 780 304 275 733 749 108 725 502 528 598 763 89 247 210 691 760 329 780 148 104 758 747 600 630 196 800 411 179 613 821 358 139 832 213 785 526 238 430 223 738 745 819 322 31 196 493 217 473 530 793 85 176 661 338 323 37 117 630 684 683 475 302 539 236 562 685 22 699 436 530 782 818 832 646 250 453 365 549 421 504 436 356 804 440 634 201 531 586 796 335 797 493 444 729 540 621 74 358 369 549 513 691 375 681 686 778 366 285 617 489 445 336 269 589 772 404 416 627 197 462 324 143 282 …
Output: YES

Constraints:

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

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