CT38907

The roads at Fungaldeep

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

It is audit day at the mushroom groves of Fungaldeep. Nora spreads the roads 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 <= 2489; 0 <= m <= 2489.

Example 1:

Input: 2129 687 437 1125 258 1934 2084 87 1529 373 198 1449 2009 1786 26 798 49 276 452 776 1911 2015 1333 282 1191 1240 974 2100 602 97 1024 184 900 1675 1264 1192 1401 474 1509 937 528 916 1677 2112 1397 362 805 1351 651 1367 271 1063 1893 1552 1741 80 446 451 274 684 692 91 315 1854 1106 2102 1420 1600 896 1529 783 2091 105 2109 878 2043 1088 237 198 1914 1478 1035 801 1154 605 1789 1677 1679 1715 1855 230 733 614 210 1134 1791 1951 785 1514 1312 2025 924 875 1209 549 1574 1760 1678 1751 69 394 2105 106 1447 123 1708 737 618 102 543 1520 1931 868 1534 1287 1134 123 1540 1196 998 1597 1031 1559 1405 66 469 2020 1754 1020 1372 155 1097 807 1623 364 1447 1604 78 335 1004 43 1374 1450 658 2122 1897 1132 32 624 1044 1785 1545 685 1687 983 3 801 1021 882 1233 1960 616 1481 358 632 1246 1115 1653 102…
Output: YES

Example 2:

Input: 1758 1161 1455 302 222 276 508 920 501 1140 828 895 1451 1669 1296 837 1031 381 1269 295 1269 943 128 549 1731 1416 968 442 620 1001 1567 927 1550 913 871 523 306 17 1265 719 1645 182 281 813 97 379 1390 676 1504 1252 1733 1737 1055 1607 823 1564 1540 506 274 662 1227 1000 199 395 1545 56 663 1413 1259 144 1567 544 665 65 1218 121 1245 226 813 1249 582 8 277 508 924 1101 1051 1188 151 1314 1648 309 606 142 1218 826 1650 1398 61 275 1290 107 679 390 903 1320 235 1026 770 425 1548 943 245 1381 1345 716 409 159 1721 470 328 584 20 659 1091 1225 1200 1095 1394 964 497 1603 1751 1431 1225 1408 231 801 1436 310 278 1651 1508 612 656 1219 754 53 179 1056 1511 596 879 1425 645 351 1550 561 1404 1707 1293 463 1235 508 1702 585 818 1605 835 608 916 174 771 1612 1289 454 971 765 383 198 1614 1311 992…
Output: NO

Example 3:

Input: 1213 2107 615 322 135 1180 409 310 441 170 346 758 59 1043 49 446 1200 1152 393 921 836 438 1134 466 262 886 172 178 639 1213 1023 773 652 1141 549 384 890 685 267 257 326 741 260 171 1205 474 1150 61 1060 189 1183 1148 980 257 686 481 80 688 17 187 855 401 920 673 1203 1151 460 1028 466 462 462 1054 530 955 278 208 1065 842 963 199 470 1146 706 171 466 3 372 36 506 370 603 68 1170 663 1073 1122 231 172 693 466 129 1004 32 729 791 133 563 882 950 521 94 427 672 946 470 280 126 834 1075 1049 921 481 925 757 669 433 618 912 1082 347 940 663 195 156 11 227 967 786 843 1070 1136 1205 926 587 508 26 1033 1012 609 350 1189 430 786 90 863 112 796 420 489 965 863 174 1186 18 976 1205 1102 297 1106 1 1033 299 718 600 949 413 397 1175 431 480 1080 105 1097 843 1095 398 309 1061 100 28 178 569 1199 4…
Output: YES

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The roads at Fungaldeep - MEDIUM Coding Problem | CodeTikki