CT56975

The Caravanrest Circular Route

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Every season at the dune sea of Caravanrest, someone must map a faster supply route. This year the task falls to Scribe, armed only with the canals register. 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 <= 2324; 0 <= m <= 2324.

Example 1:

Input: 1776 265 1097 1337 1535 798 841 409 813 1168 260 1675 630 1721 727 138 1550 1263 424 302 383 1325 190 13 1114 928 378 1088 101 459 461 610 453 1616 472 233 455 312 910 1339 1153 921 1169 1114 111 556 781 871 10 414 1238 1084 1212 590 1318 1524 805 194 907 249 167 1773 643 1331 1109 1404 435 50 1289 351 47 1512 1098 1485 215 1522 581 1071 467 1472 1381 1160 1456 660 605 936 52 1200 542 917 1131 691 837 827 1060 673 361 1678 1450 1601 1533 285 490 1498 914 47 809 19 988 174 797 1590 652 399 1729 153 309 1611 1134 615 363 1569 677 222 472 1132 680 930 1306 1603 1646 890 424 817 815 852 373 594 596 191 1515 1502 706 930 1009 694 1167 1338 859 801 1432 1254 1529 1199 1055 28 747 679 829 469 1753 1315 519 214 590 214 1610 1472 818 795 1443 1138 58 855 1064 566 801 1211 98 1503 768 1702 1461 321 …
Output: NO

Example 2:

Input: 1223 1453 158 987 921 585 625 768 1061 454 776 740 701 316 727 367 1213 872 746 899 1100 1149 1035 343 700 507 62 53 854 372 1109 530 399 350 351 363 832 522 1045 206 279 533 1114 1024 929 213 391 470 729 650 875 1059 91 501 659 679 171 17 482 884 709 510 1145 1162 252 449 843 1136 127 800 512 994 857 754 381 1046 368 626 511 1080 800 347 907 1157 958 1103 1011 789 1143 310 1123 88 186 303 664 193 184 682 1134 72 901 527 805 341 270 83 633 163 360 422 247 396 823 416 637 905 497 29 366 176 79 20 641 1188 1008 547 502 130 1164 62 579 1212 105 213 467 816 714 600 1003 411 707 24 104 1032 629 254 349 524 867 430 1016 163 624 500 134 809 651 572 697 530 911 669 1099 1197 600 320 878 268 326 99 466 243 172 1134 865 1192 651 24 1200 856 725 325 927 268 777 533 246 1007 1219 219 1002 105 190 620 …
Output: YES

Example 3:

Input: 119 696 18 48 60 88 97 7 113 74 67 34 17 39 83 24 8 81 34 26 81 1 114 62 75 76 114 64 59 104 113 21 80 102 32 38 9 28 16 106 58 116 60 107 18 31 107 12 50 89 10 7 75 90 61 28 5 28 18 113 27 50 1 36 8 36 12 45 85 113 94 80 119 16 56 37 30 18 57 86 7 28 116 83 1 93 2 68 25 66 101 55 87 119 16 78 16 95 10 51 63 48 33 28 37 110 35 39 111 66 80 57 40 65 42 81 1 2 84 104 111 27 23 12 11 24 39 7 16 21 15 106 110 31 22 118 24 76 43 81 31 23 101 42 48 69 22 109 77 87 87 68 74 53 31 86 107 72 77 115 55 83 30 80 47 92 92 53 100 92 88 92 111 106 38 93 116 85 79 81 74 30 20 14 115 69 107 114 26 49 72 9 115 100 85 50 61 30 76 70 71 111 100 101 43 95 25 98 55 110 70 115 4 69 106 73 91 73 34 96 59 61 110 61 32 21 52 98 68 25 119 80 25 75 27 75 10 22 26 42 97 69 72 71 26 2 62 51 79 117 28 69 62 100 11 77 2…
Output: YES

Constraints:

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

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