CT42727

Sailor's Circular Route Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Legend says the vault under the lantern lake of Firefly Mere opens only for a perfect tally of bridges. Sailor 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 <= 1267; 0 <= m <= 1267.

Example 1:

Input: 57 944 14 26 26 20 25 26 51 33 54 23 34 39 43 26 53 20 39 27 15 39 35 41 5 49 7 38 2 4 49 15 15 51 45 54 23 11 18 17 12 25 22 33 20 57 33 39 14 41 3 55 54 6 56 1 34 17 22 37 44 42 6 28 30 25 28 29 41 18 49 11 1 21 17 21 49 12 1 9 50 17 3 13 27 31 43 17 40 42 41 15 7 26 1 44 14 3 31 44 50 38 33 43 17 5 49 57 57 31 15 43 29 47 12 53 28 24 20 14 33 45 8 33 38 30 21 44 42 21 22 39 11 15 4 26 25 39 33 9 45 47 40 26 57 34 42 7 35 45 9 46 41 3 9 21 44 52 43 54 8 44 43 10 31 9 36 9 36 19 49 26 41 19 1 35 28 43 34 51 27 56 34 30 11 20 22 49 44 45 48 1 46 56 22 32 14 38 2 38 30 34 23 29 5 10 47 26 5 7 43 50 27 41 57 47 1 32 47 40 44 57 17 49 54 25 30 43 29 8 15 21 57 44 38 21 57 51 15 38 25 44 53 21 54 30 44 40 2 1 53 38 9 37 41 14 2 43 53 13 28 12 44 10 53 43 1 55 23 45 38 48 49 23 22 5 28 42 3 4 5…
Output: YES

Example 2:

Input: 763 1242 285 510 212 29 139 257 22 213 61 695 4 376 335 43 487 568 398 543 592 340 286 111 128 707 736 516 404 635 646 681 722 221 419 109 42 492 244 582 412 98 117 280 539 656 492 107 715 78 574 61 28 10 24 470 196 139 553 383 247 348 519 346 30 470 273 762 226 441 514 558 74 145 682 331 731 133 427 544 105 563 534 760 96 134 354 258 166 581 117 580 320 622 632 61 479 290 743 617 436 167 588 360 226 479 147 407 4 680 714 130 117 1 631 122 529 470 442 606 352 267 7 254 665 53 207 50 613 88 634 87 693 267 493 673 97 497 645 3 538 117 445 684 663 505 33 697 246 350 299 619 303 705 639 677 188 559 341 42 182 422 678 206 205 271 207 155 410 540 244 642 99 702 158 344 744 565 138 658 28 694 482 614 437 593 481 225 440 569 427 569 243 320 266 504 414 35 617 182 329 195 451 570 689 557 512 209 19…
Output: YES

Example 3:

Input: 1225 47 700 106 26 873 341 400 1149 518 1056 495 362 659 728 918 1044 1139 1096 745 1207 90 259 1195 160 217 946 844 611 102 1003 1183 124 1058 724 254 663 870 734 861 196 1114 164 651 545 625 788 325 994 168 27 79 476 488 315 428 208 824 618 1018 1129 306 375 720 138 99 1027 106 131 378 1 1174 715 571 705 514 130 232 625 1144 116 940 718 156 813 840 992 163 375 721 1087 444 84 85 472 1000
Output: NO

Constraints:

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

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