CT48174

Ishaan's Brass canals

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Ishaan inherited the apiary at the eel marshes of Slitherwick along with its curious bookkeeping system for canals. Time to make sense of it. 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 <= 1750; 0 <= m <= 1750.

Example 1:

Input: 1079 919 1036 811 708 382 853 324 851 170 62 614 904 276 670 243 405 892 323 907 370 379 598 564 894 43 140 174 221 755 899 72 499 978 573 10 161 295 661 426 341 88 425 117 66 994 330 811 289 68 1049 873 255 69 877 361 50 592 1019 102 544 354 55 1005 635 944 136 362 971 1022 191 895 964 995 596 307 1078 274 515 595 870 76 1031 910 682 1075 1053 426 798 818 135 811 717 959 566 878 326 1004 950 885 380 356 58 465 1 907 491 170 115 168 709 894 833 816 633 704 119 125 5 71 1047 202 553 408 734 258 590 239 256 504 185 1024 466 37 854 341 618 204 1032 1021 1069 609 748 151 807 175 570 754 1057 115 34 750 329 1002 583 91 218 31 122 633 801 182 1052 47 312 99 538 966 701 868 522 212 1008 830 77 278 191 903 389 847 463 210 689 394 691 633 810 293 934 336 784 209 900 519 402 388 21 338 426 342 969 6…
Output: NO

Example 2:

Input: 773 781 105 86 116 730 374 175 665 720 344 97 555 189 593 596 582 577 587 470 344 307 709 705 22 724 306 20 85 472 441 302 634 200 27 23 69 316 202 320 539 202 246 752 3 131 484 460 469 215 283 85 746 67 46 499 355 631 388 341 470 1 56 358 634 570 173 474 425 466 2 466 360 199 329 687 730 686 388 217 217 117 27 278 565 481 364 501 521 364 685 252 451 405 600 433 24 596 749 470 732 611 571 316 454 324 231 519 267 353 726 339 44 704 685 159 287 434 324 133 527 385 526 70 752 156 181 17 308 91 89 233 24 246 715 510 395 214 574 177 251 680 512 459 733 666 464 19 324 527 182 543 714 22 623 346 32 527 499 771 455 541 182 26 731 560 9 663 617 447 655 539 360 445 7 516 249 281 241 615 415 421 161 14 274 758 579 465 42 100 57 478 19 672 665 35 570 381 523 150 487 139 428 551 550 421 415 330 574 731…
Output: YES

Example 3:

Input: 1607 2 455 1307 1428 1071
Output: NO

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Ishaan's Brass canals - MEDIUM Coding Problem | CodeTikki