CT54440

Ysolde's bridges Circular Route

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Every season at the wren hedges of Thimblewick, someone must secure the caravan contract. This year the task falls to Ysolde, armed only with the bridges register. 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 <= 3671; 0 <= m <= 3671.

Example 1:

Input: 2205 1047 584 1028 1509 48 727 870 1244 1843 779 318 444 1048 1280 252 625 1968 1399 1515 2082 749 689 1625 77 865 1199 1388 1142 1645 2080 167 732 627 602 2004 395 1678 1462 1354 413 930 1293 1354 1501 2201 1840 942 252 1562 1479 847 2143 413 389 1656 680 2164 1961 2199 311 760 652 1535 949 815 1685 675 1951 523 1600 460 343 1076 757 126 1049 2169 147 1393 1260 499 1134 2000 1796 2141 2200 1780 1351 1104 300 1411 1961 146 22 1279 1119 1074 893 1752 851 176 467 441 537 429 446 1910 1451 1405 198 1542 918 1250 2043 1747 1992 974 904 1775 693 1834 1344 2180 1990 1993 628 1547 47 1596 966 1924 1766 1672 2002 1314 1129 1147 949 130 2201 1376 1932 1795 515 1636 1038 1903 1734 1887 1974 160 165 751 1333 1179 1448 606 966 119 1029 1197 23 305 1975 323 571 603 637 1363 1283 1113 135 1184 2072 1283…
Output: NO

Example 2:

Input: 3623 2957 1248 1322 2586 2680 2341 1571 2313 1370 2563 1434 3552 1643 1798 770 2302 68 3460 2206 1973 1301 2202 516 1777 3096 135 3014 889 3536 3071 1912 2200 3005 206 3422 616 1851 566 603 1202 437 2644 290 3584 3183 2368 62 2262 2496 2973 1200 377 1535 1548 3021 1240 2288 2198 1414 1032 922 1996 1453 2172 303 1276 3197 2638 3494 490 2877 2558 2982 1552 1677 1544 799 900 2139 3403 1112 941 1034 639 2995 234 3186 723 3614 1618 358 3349 1803 2143 1693 1730 557 313 1319 1352 3550 4 84 2637 1468 3396 3567 89 123 1858 3562 711 3301 1367 2685 2138 2626 169 1854 1425 2385 2347 1933 2700 2232 1625 3498 1809 1815 977 1842 1683 3174 2526 2496 1925 2256 2892 1268 1835 1825 90 805 439 466 3392 2867 3288 1914 5 2986 986 1415 322 467 2320 408 2064 164 2864 813 3098 1038 3110 2003 135 896 552 1973 424 3…
Output: YES

Example 3:

Input: 1194 1737 70 474 87 254 590 1139 17 1079 128 1167 33 798 153 480 702 655 28 964 549 994 133 635 223 28 1063 187 285 503 528 390 586 392 824 468 220 608 405 428 116 1003 433 97 595 654 370 1155 1194 214 161 972 253 879 921 833 1028 819 553 297 1127 645 896 968 215 795 362 67 1063 740 81 911 595 200 1098 828 42 875 578 402 192 480 127 899 959 555 1009 702 522 1026 377 944 320 1065 632 441 705 993 149 576 1100 1187 886 835 53 195 996 921 1111 806 910 507 951 176 152 222 203 1184 132 993 768 814 904 871 891 130 1016 443 696 62 1124 446 829 994 340 1150 1160 835 398 1038 647 1080 167 258 916 36 1098 232 799 1100 1019 505 880 53 199 1059 39 697 1152 863 1072 608 1063 311 893 578 972 175 835 788 887 337 1170 266 828 216 956 1044 309 959 1115 582 236 310 13 1052 924 8 524 580 127 701 1117 288 1076…
Output: YES

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Ysolde's bridges Circular Route - MEDIUM Coding Problem | CodeTikki