CT37944

Curator Counts the tunnels

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Legend says the vault under the gristmill of Rye Hollow opens only for a perfect tally of tunnels. Curator means to find out. 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 <= 3891; 0 <= m <= 3891.

Example 1:

Input: 770 1341 393 209 128 305 741 539 392 590 478 404 396 132 302 703 181 185 745 758 338 369 558 604 431 664 163 255 68 85 653 568 691 300 312 383 5 137 698 526 121 653 166 307 511 504 295 683 611 70 195 586 660 69 605 652 191 540 737 506 541 147 625 704 468 254 664 139 756 752 667 627 74 647 428 479 631 446 398 31 487 262 465 612 492 460 457 476 722 411 574 543 32 499 762 393 749 484 235 106 66 331 683 374 182 711 498 292 767 547 94 297 70 156 601 329 521 89 398 352 126 99 111 243 397 682 643 157 528 553 649 135 429 18 155 222 158 568 344 70 456 166 706 189 62 128 290 332 143 214 522 265 426 676 706 597 16 309 711 254 179 367 321 120 242 701 424 501 333 702 382 26 334 142 251 93 133 228 475 583 119 509 405 301 678 248 161 211 221 194 286 183 124 373 405 507 132 222 21 644 288 693 147 590 25 4…
Output: YES

Example 2:

Input: 3310 2366 2291 614 702 245 1109 1261 1894 1619 3152 1681 2599 1397 1998 1497 1030 1268 813 1468 1932 1604 247 543 3060 2135 1550 1254 3152 2581 1847 2737 1160 965 2104 1493 2463 2350 777 17 1400 1018 2710 1559 613 2263 17 300 1464 76 947 1974 1592 2714 1537 546 1762 1401 2800 1144 1389 2281 1974 1465 1851 1889 1423 474 2072 728 345 1219 43 2139 1734 62 1922 1465 3031 1022 2587 2609 1491 1862 2659 1160 898 1591 2687 820 1345 830 1835 87 1224 2076 888 3169 1893 2993 920 604 3104 335 2190 347 2781 987 2187 2252 1515 1032 882 1732 2547 1461 1983 3267 3221 2534 2249 3246 1022 2251 25 790 2188 1566 2847 2124 545 2142 2321 3210 3303 484 756 64 896 959 2121 1560 2155 2312 1203 2269 2456 243 2765 2440 2440 1994 3146 2360 2102 2427 1080 1352 619 1894 570 951 2763 2893 3168 1111 1498 504 2268 1527 23…
Output: NO

Example 3:

Input: 414 1005 47 298 276 100 345 175 62 114 57 130 204 354 94 336 242 368 64 59 340 395 338 208 67 192 47 56 182 315 286 344 144 5 212 348 359 132 266 94 263 249 62 355 71 157 304 142 126 169 205 242 65 264 260 233 340 44 184 300 304 251 403 308 245 185 20 317 26 251 265 363 245 113 31 22 3 412 200 77 10 56 400 369 279 347 43 163 99 332 278 304 268 111 302 221 124 133 216 367 49 290 377 31 88 361 181 82 61 11 165 178 30 349 410 164 179 76 298 295 357 279 2 110 143 66 59 392 109 337 242 172 152 224 162 254 53 290 394 330 87 31 91 205 37 321 246 164 284 331 59 124 121 238 175 211 254 305 288 104 303 368 346 260 43 255 339 150 145 107 304 187 14 371 142 303 343 12 30 24 177 15 123 259 4 136 395 60 269 345 106 248 146 191 69 133 41 121 188 164 310 407 66 170 299 18 361 35 201 246 231 371 216 316 89…
Output: YES

Constraints:

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

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