CT45255

Chavi's Faded roads

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The reckoner Chavi has been asked to settle the inheritance fairly. On the desk lies a long table of roads readings. 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 <= 3029; 0 <= m <= 3029.

Example 1:

Input: 763 2388 729 762 254 634 432 536 341 15 383 654 482 279 228 61 220 339 697 192 201 261 294 334 594 499 563 6 28 327 305 679 363 722 549 702 567 597 418 586 267 668 4 693 386 99 622 683 79 93 86 695 525 569 139 423 709 232 569 339 60 392 738 33 673 275 80 679 743 697 368 500 474 279 454 495 248 453 405 331 296 726 501 701 662 379 295 276 275 31 170 183 556 158 500 296 241 314 362 627 526 332 724 115 251 712 450 394 629 427 213 414 361 589 550 333 167 622 432 403 701 728 474 195 364 326 201 83 338 120 364 622 663 220 675 5 756 466 401 21 410 545 375 417 269 434 415 462 140 68 56 718 301 704 566 654 293 580 217 699 191 110 302 420 298 733 189 523 673 727 199 689 270 603 45 182 604 35 192 750 181 641 567 537 209 731 727 287 635 69 223 636 262 500 649 684 514 94 567 313 613 594 247 59 661 409 1…
Output: YES

Example 2:

Input: 151 144 97 54 146 70 21 39 132 118 26 117 26 13 37 30 38 51 129 89 128 23 22 127 143 67 120 17 49 5 48 127 80 118 16 62 110 136 150 98 47 142 120 49 73 85 58 52 111 87 80 88 7 29 10 146 136 111 62 111 47 74 100 113 55 104 6 52 22 133 123 142 1 91 147 105 126 137 44 15 142 65 85 53 4 21 129 123 145 14 41 119 106 126 44 58 126 46 72 123 146 97 55 7 48 55 45 59 89 101 63 42 1 129 79 1 93 35 70 79 73 119 140 142 12 114 67 74 79 94 78 140 136 9 77 21 133 50 137 30 26 52 94 64 131 16 109 126 69 67 22 17 86 123 72 64 93 38 109 2 132 102 49 142 122 78 54 111 45 151 40 34 139 54 143 50 60 50 101 75 25 76 72 144 92 101 59 67 92 87 83 8 44 119 111 52 4 130 48 105 130 34 16 148 98 84 117 107 21 34 61 97 19 84 113 37 113 146 77 75 75 128 147 9 116 36 16 147 119 34 143 68 68 110 1 102 147 90 8 46 109 13…
Output: NO

Example 3:

Input: 1272 1029 136 670 1180 18 880 151 225 697 1218 1161 127 357 954 582 126 12 485 755 517 272 809 585 797 1027 743 71 960 1049 965 7 1100 23 1195 1064 824 816 1001 720 542 93 1010 1270 800 867 916 367 511 765 235 1095 1044 412 1075 107 479 396 1197 157 585 973 521 1249 7 1018 850 796 811 1248 215 821 1109 438 639 1069 617 194 189 184 1169 732 392 117 1244 147 105 550 138 589 928 698 368 1149 550 582 71 582 1254 1063 374 710 1164 388 677 970 585 689 583 361 1017 560 214 818 1053 1227 101 561 543 1212 1127 264 1222 158 593 913 158 913 222 1080 209 1185 1232 802 169 1084 895 480 95 714 1075 296 819 1050 542 630 1212 1134 520 727 293 743 320 285 358 69 641 417 292 757 1008 789 379 279 757 392 629 454 389 570 1043 204 656 37 366 107 1098 49 340 894 384 1116 1032 12 904 37 252 679 978 177 931 254 2…
Output: YES

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Chavi's Faded roads - MEDIUM Coding Problem | CodeTikki