CT42713

The Circular Route at Rootwater

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Morning light hits the mangrove channels of Rootwater as Tanya unrolls the day's manifest of roads. 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 <= 1020; 0 <= m <= 1020.

Example 1:

Input: 996 627 67 913 893 468 651 901 844 988 704 59 591 808 482 17 317 250 69 883 498 955 474 127 548 794 494 445 385 143 809 734 196 921 857 80 272 837 276 638 733 866 257 287 285 661 36 825 237 691 869 306 803 272 901 740 541 183 435 831 619 695 964 211 761 597 624 905 906 881 387 814 719 291 726 783 812 453 987 203 558 680 945 730 918 318 377 457 753 412 490 971 954 478 949 584 708 229 513 570 334 699 515 692 160 800 440 151 823 545 279 370 239 867 397 548 866 141 182 431 349 476 366 756 322 636 800 120 208 644 732 73 867 948 574 580 568 202 958 516 1 414 468 750 884 533 415 29 755 686 658 256 439 684 499 786 816 823 381 91 215 680 200 888 911 355 676 823 419 527 135 525 584 640 393 900 38 350 357 368 191 888 217 513 689 871 242 910 887 374 409 784 879 797 261 91 93 189 688 334 977 156 376 42…
Output: NO

Example 2:

Input: 873 999 413 835 766 318 181 836 700 707 88 344 659 524 94 322 229 343 84 340 703 316 13 69 57 280 463 396 487 124 768 208 859 224 815 369 309 526 830 655 222 759 32 416 504 425 190 441 329 435 518 682 850 500 337 370 862 205 306 516 36 749 522 825 236 545 225 496 30 545 606 807 15 406 439 711 749 337 554 141 258 591 351 518 402 841 792 79 547 566 36 422 72 413 124 699 142 242 27 795 796 264 555 860 818 803 175 641 123 683 14 615 615 776 470 668 377 146 320 376 754 703 548 690 448 643 528 639 709 580 89 40 489 578 613 419 98 551 621 1 217 458 705 717 310 263 626 478 165 20 526 203 856 374 413 231 139 838 380 418 100 804 737 273 324 5 145 14 11 454 454 701 872 849 837 498 861 609 753 394 419 56 743 379 158 426 233 259 358 830 746 132 541 679 771 255 18 295 508 647 246 74 81 105 118 748 741 4…
Output: YES

Example 3:

Input: 274 10 52 270 134 97 99 66 71 47 53 55 216 91 118 10 167 229 11 81 274 1
Output: NO

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Circular Route at Rootwater - MEDIUM Coding Problem | CodeTikki