CT48787

Ulric and the Pale canals

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

It is audit day at the river town of Willowford. Ulric spreads the canals records across the table and picks up a sharp pencil. 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 <= 2316; 0 <= m <= 2316.

Example 1:

Input: 1983 912 1947 1640 576 561 232 1944 261 956 1242 426 364 1201 358 1147 1633 582 118 1475 1811 1545 264 1663 308 1551 1883 717 1760 1895 1189 1491 1962 452 1363 1694 437 734 1958 80 544 831 41 269 1568 1452 1702 1244 1456 1277 468 1940 589 651 1714 141 663 648 1411 78 1664 1560 891 1407 1384 1231 168 898 1249 494 553 163 1450 716 562 1402 804 1035 626 711 1751 642 459 335 833 195 1020 328 1140 571 267 1318 506 1702 1567 1755 453 1587 1395 1305 208 1014 1798 734 269 999 1043 1670 1810 295 1091 982 895 737 149 1968 29 905 592 991 1207 1881 1620 1186 1411 299 934 39 195 411 1637 837 1962 598 341 92 134 1438 293 395 1856 867 306 948 828 1259 1698 722 1279 1616 593 1298 913 1633 590 1438 427 762 259 808 762 1491 1833 1248 1713 713 577 1745 1037 1238 358 122 1039 1342 214 806 1515 469 1485 1014 1…
Output: NO

Example 2:

Input: 1270 1596 589 348 1046 676 461 907 707 175 659 416 919 63 359 649 682 245 924 15 73 528 887 392 734 289 217 104 804 1004 149 794 1004 632 609 584 1255 780 570 938 438 405 621 738 72 211 290 516 468 1132 1181 338 629 908 120 700 1214 216 1177 1076 868 1147 377 600 680 61 436 790 171 417 1112 614 940 877 227 22 1067 350 85 201 512 76 66 1243 948 1113 1248 1065 177 481 771 456 964 1088 132 1141 866 308 225 257 133 923 162 729 1220 189 568 136 324 167 984 114 243 759 1135 234 442 564 994 875 1063 1248 30 830 129 889 452 645 383 633 199 409 307 259 387 471 668 990 175 362 449 84 1264 69 200 1203 390 938 990 984 1180 886 337 218 57 616 607 889 164 130 381 94 855 402 101 1125 938 224 541 639 210 300 190 405 1058 741 303 976 495 1156 742 294 313 714 378 1065 60 66 495 817 782 21 1236 356 943 1127 …
Output: YES

Example 3:

Input: 2100 1649 325 1937 1053 648 260 1784 935 1897 1740 1784 1322 586 1494 1981 618 606 361 1268 839 1033 80 1000 1107 225 881 145 979 1587 843 840 707 2031 1194 793 1450 580 28 1166 1816 1385 1150 508 1736 1607 1182 1860 700 1184 1924 2034 1654 1937 262 668 472 1159 1507 1259 1135 1192 1832 693 921 1285 1917 415 402 606 56 611 1488 4 1180 313 1258 1967 1675 1142 40 243 670 1276 2096 802 747 528 2025 1159 1329 1802 1423 352 1758 644 1835 1100 922 566 1620 1158 1102 544 1000 1393 1523 1760 1745 132 950 1684 883 1438 502 2021 1995 516 1348 395 1743 1836 1378 1010 552 1760 1795 1399 503 447 1186 213 257 815 950 680 1054 903 1873 2016 1544 1731 777 717 1246 753 987 1043 1090 1740 1862 305 450 141 1768 1654 1642 1881 661 1068 1837 2033 1090 1549 1945 1767 1604 932 462 1576 1041 367 742 1139 1180 130…
Output: YES

Constraints:

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

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