CT51351

Ojas Counts the roads

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Before the gates of the glass towers of Prismhaven close for winter, Ojas must finish the roads 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 <= 2952; 0 <= m <= 2952.

Example 1:

Input: 553 507 27 350 82 117 11 513 40 173 359 159 533 78 190 304 334 425 53 21 305 155 67 171 396 299 138 212 127 544 289 111 530 88 269 26 63 88 150 417 426 370 369 108 492 185 161 252 412 484 358 390 305 521 57 79 203 60 188 308 218 129 294 247 454 324 79 535 14 400 197 3 374 94 325 237 422 232 396 348 327 534 373 53 164 99 152 549 469 534 536 226 132 58 133 225 481 401 174 499 141 304 21 12 112 348 526 392 537 189 21 259 48 381 529 42 40 515 426 422 385 304 417 541 375 85 137 315 370 34 201 113 454 306 523 22 440 510 162 307 480 536 238 514 481 184 529 309 343 489 532 10 323 450 109 387 407 477 141 280 538 310 240 461 242 261 522 242 386 524 299 443 7 497 471 118 31 36 177 232 158 398 221 544 410 223 460 246 121 372 191 243 531 377 112 73 170 439 303 118 330 491 73 254 436 521 218 473 461 284…
Output: YES

Example 2:

Input: 2833 2210 1510 2557 2751 883 132 268 2772 543 2559 713 1372 1024 1511 2700 38 1972 914 1074 1802 1000 141 2256 1650 2501 1481 1568 911 325 2556 2413 435 1900 537 1030 1560 1768 1660 1682 167 2252 354 2041 2063 2281 314 1274 1447 2228 2586 1008 440 532 2119 300 910 126 860 208 1473 1280 2804 2825 2637 1516 1533 815 401 1076 1309 1905 1101 612 1445 2530 2289 2714 479 2320 881 573 1357 1993 204 1166 977 2472 2416 551 337 319 2435 1394 2067 2590 809 1504 1108 488 335 1096 624 1868 1619 1489 1287 581 215 1334 2814 2198 600 1765 1114 2318 577 735 297 1131 1983 1367 1970 337 288 1191 1883 286 2479 135 1323 520 1546 2826 1815 864 2829 1929 1981 2663 2284 1887 425 2624 1067 437 2523 697 1847 1015 2310 699 548 2131 232 1792 2014 2552 2332 2268 1301 1405 836 1813 302 992 1416 818 965 530 459 1610 243…
Output: NO

Example 3:

Input: 2944 1926 2002 2020 2256 2828 1269 2203 1084 521 347 414 99 803 1387 1198 963 2171 2843 433 977 1133 1803 1482 669 1049 2528 2247 2283 882 1826 2696 2886 688 2040 1051 1161 776 2535 2390 1305 123 2415 453 613 1389 1585 1505 1288 43 1752 2812 2892 2429 2382 57 1350 2523 2810 210 393 2653 130 1828 1096 916 437 1806 961 2014 543 2572 2715 1738 2313 2745 820 2798 2335 2265 1059 1720 2831 711 173 2166 2164 1896 946 668 2167 1988 2420 883 2922 1016 2730 1596 1607 990 1766 1798 1189 1871 1340 1025 2321 1278 129 1259 2390 214 666 704 2762 1756 1554 602 2790 933 2169 1670 901 2616 1407 2316 253 2397 538 1348 1318 1529 1415 2887 1990 2892 1648 2584 1096 2506 761 2589 1778 797 413 495 483 1962 1852 1704 2712 884 1268 1714 182 199 1186 2923 14 648 2774 1676 1897 2518 15 623 907 663 312 2282 480 363 25…
Output: NO

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.