CT43083

The Golden Circular Route

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

In the beacon hill of Lantern Tor, Brevin the tallyman keeps careful count of the canals. Inspect the delivered goods, every figure matters. 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 <= 2016; 0 <= m <= 2016.

Example 1:

Input: 1045 133 86 461 282 798 386 211 678 22 167 557 483 942 904 499 432 549 816 389 907 507 942 663 123 530 354 552 275 249 495 545 288 545 864 436 972 827 578 912 742 866 806 508 660 427 204 298 262 505 263 995 944 514 839 891 668 501 1014 80 430 2 633 169 733 315 231 449 66 835 811 292 748 103 168 98 588 100 677 866 854 207 220 1035 219 360 122 1001 591 946 431 548 576 715 494 850 464 148 306 698 512 580 968 897 778 808 370 405 24 340 956 267 215 609 363 693 177 677 912 92 891 871 319 553 146 931 233 319 155 419 325 103 628 226 980 654 683 742 222 745 555 716 486 445 168 779 596 8 568 653 121 15 105 547 763 553 31 814 260 245 848 1024 404 718 626 811 488 737 577 456 815 257 803 229 559 306 257 8 501 770 896 227 951 305 889 703 938 60 581 540 263 701 812 75 518 149 183 888 276 492 595 278 3 78…
Output: NO

Example 2:

Input: 947 1902 155 594 125 470 60 913 594 704 676 937 508 120 656 146 533 859 336 685 369 271 335 376 901 891 658 116 87 55 374 247 902 237 611 261 901 76 591 505 917 691 279 290 883 504 483 523 191 221 242 411 787 316 313 52 672 623 160 242 418 859 474 582 565 474 940 760 494 187 347 740 731 438 837 925 362 726 677 870 719 20 426 355 885 650 344 322 712 350 939 608 371 2 555 626 881 947 87 143 719 350 936 251 87 238 616 914 403 865 218 4 429 31 654 409 896 839 42 578 199 714 354 219 391 275 854 640 282 639 291 223 29 792 794 83 667 329 96 426 335 203 945 921 910 478 355 813 232 451 588 744 756 194 784 435 530 210 899 536 383 785 161 75 20 201 195 675 218 903 412 64 614 866 649 553 96 205 734 83 685 57 161 594 59 714 585 29 517 405 648 259 331 633 541 722 75 626 711 104 938 807 379 702 362 937 5…
Output: YES

Example 3:

Input: 1655 2012 1652 668 1504 1268 1114 1568 236 348 1379 475 60 282 959 694 636 204 1200 1624 1227 161 364 855 466 57 803 1127 382 953 390 715 471 137 672 1066 242 181 1376 34 401 1255 1220 1264 140 464 70 1089 1152 1518 1041 681 1162 130 1410 1201 440 1307 1490 1276 256 686 602 617 1096 1501 1258 982 681 388 795 1577 1468 484 192 1463 1420 916 632 442 1281 538 15 1647 1341 661 988 96 119 467 1069 1421 205 1124 397 808 796 35 652 257 478 291 825 3 1211 242 218 803 490 245 550 627 1068 22 110 723 1435 194 672 1231 529 139 1480 737 620 834 750 1077 1100 1550 524 1427 1481 375 352 1300 54 1065 73 1140 659 1129 1492 791 373 1464 1367 521 803 629 652 1523 427 1033 1454 696 454 85 1214 1014 409 1162 943 1145 1200 1251 575 1505 67 1654 1067 1528 650 603 246 636 600 302 1507 385 1534 481 326 1158 123 1…
Output: YES

Constraints:

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

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