CT54481

Lara's Ledger of corridors

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Morning light hits the alabaster quarry of Whitestone as Lara unrolls the day's manifest of corridors. The tally will decide the next shipment. 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 <= 3319; 0 <= m <= 3319.

Example 1:

Input: 2949 2399 899 2523 786 2289 2772 572 2537 705 1812 311 2915 844 1377 2661 274 1177 563 2598 2325 779 1781 2423 1032 2678 1412 1369 2283 1208 1140 391 105 1027 2424 2403 1404 1783 566 568 2073 1666 2247 1827 2771 2750 2305 756 2923 445 2631 112 2784 211 2571 2498 337 1968 990 1281 21 1861 1507 2851 540 2450 1174 1369 2225 2790 1752 2415 2588 893 102 1484 982 1281 2039 501 2932 461 1048 1490 2883 2652 731 2084 214 2056 2316 527 1598 246 461 1759 1491 2680 2649 1014 683 2417 131 2222 146 2395 156 571 341 2095 935 1443 1859 349 2501 2788 813 16 453 2245 2156 1053 249 247 1008 14 223 2385 2610 450 2485 1176 2744 2584 2469 1171 510 2476 1676 1866 1171 2081 1501 46 2419 2185 1033 2568 1400 2507 1828 460 206 2284 2081 2629 190 1393 1206 1490 2129 2490 1822 1497 2080 878 1526 1445 1522 584 1631 200…
Output: YES

Example 2:

Input: 376 671 50 192 223 346 21 62 11 298 313 48 159 346 50 309 60 61 2 142 85 271 227 162 260 324 20 140 31 146 371 194 111 25 170 43 102 359 90 299 370 312 208 255 79 365 152 338 123 192 148 49 29 203 59 371 200 306 344 289 259 330 300 97 138 202 143 308 33 217 349 345 171 47 178 127 279 210 344 158 266 95 119 175 149 303 111 218 366 101 256 276 201 50 13 200 138 50 362 211 114 112 76 248 34 169 151 216 95 180 108 267 212 301 317 29 79 166 232 189 311 302 201 85 55 128 367 276 355 33 157 24 10 308 25 143 96 220 290 39 80 150 86 9 207 226 269 28 232 147 93 373 118 326 357 160 301 228 114 160 70 280 100 327 135 122 287 178 341 280 109 265 170 307 275 329 3 328 307 178 161 324 135 375 26 292 118 248 354 308 139 182 319 104 3 193 182 291 238 276 1 87 230 21 201 263 334 196 2 6 53 29 26 324 70 89 2…
Output: YES

Example 3:

Input: 3107 2872 1057 1865 2627 1157 3034 1920 473 2320 2276 1399 2111 673 607 1538 665 886 2183 1229 2100 2775 2468 1956 913 1320 633 1758 800 2705 2616 2726 1036 1686 1791 944 365 42 1754 825 2498 2193 481 1859 2985 581 117 311 267 1014 2718 2698 2278 2729 2877 84 2026 1823 2595 3042 126 508 1077 2080 2933 2011 807 2167 2630 909 640 234 2202 1749 703 386 298 236 2922 431 1694 2885 3044 2076 965 745 145 139 2313 93 2458 1528 1022 1755 833 1363 640 1464 1485 2857 2565 208 1994 784 1836 2645 862 2438 678 2641 622 2890 1722 227 2095 1309 1276 1901 2768 528 245 16 2594 2633 343 2831 871 3060 699 2209 2983 2457 2876 92 3021 2235 1287 2526 1291 2306 142 3060 2516 516 1285 2607 1837 1509 378 2194 541 2699 1102 570 748 951 373 2129 2333 1163 842 738 405 813 1618 1530 2180 1737 426 2675 2543 843 2869 210…
Output: YES

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Lara's Ledger of corridors - MEDIUM Coding Problem | CodeTikki