CT52286

The Brass Circular Route

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

In the thorn maze of Bramblecourt, Farmer the registry keeper keeps careful count of the routes. Audit the season's records, 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 <= 3452; 0 <= m <= 3452.

Example 1:

Input: 799 2388 581 563 288 225 231 612 114 465 48 634 778 756 166 662 746 665 673 434 3 66 49 443 195 609 607 245 166 618 313 343 31 732 83 754 250 199 788 528 54 107 595 752 448 106 520 498 763 777 130 238 295 626 314 702 573 282 471 87 507 256 719 610 667 265 306 241 147 372 480 699 762 330 6 540 301 121 34 641 283 742 332 43 298 231 262 716 462 377 544 106 664 796 360 406 771 280 671 209 481 665 115 607 149 89 232 2 419 406 277 271 609 272 416 389 60 74 721 96 284 395 652 501 378 580 690 530 3 618 448 272 34 716 169 91 138 321 222 553 488 541 738 434 677 339 15 240 373 377 474 719 408 569 168 649 745 716 367 475 690 92 665 158 499 438 86 168 217 257 673 63 527 198 497 651 171 168 247 254 501 770 304 392 722 512 557 210 263 545 28 772 291 534 623 373 460 29 267 369 235 445 282 318 297 139 523 …
Output: YES

Example 2:

Input: 1157 397 673 778 636 869 1097 821 933 1012 1137 219 736 1143 914 1120 994 400 292 152 1011 141 169 996 1157 686 824 101 1065 30 820 479 1015 1114 292 266 322 1087 516 210 337 64 466 683 1107 220 786 349 609 695 468 45 407 668 691 980 720 443 883 513 805 749 97 814 106 751 222 533 116 582 839 507 901 321 150 1136 665 722 1118 382 251 721 783 57 151 395 710 508 2 407 739 430 181 705 332 761 379 1114 25 366 964 827 489 1149 561 1148 735 705 887 64 108 358 1152 919 588 451 234 566 487 666 212 1010 316 531 1140 737 711 270 241 816 269 1146 846 157 407 30 409 141 21 850 82 418 1139 628 199 960 147 134 471 832 52 918 26 653 1028 304 847 547 916 540 763 758 336 382 20 150 930 475 838 775 825 476 277 108 880 416 420 435 222 801 84 1061 179 955 863 589 182 446 693 1038 429 1038 459 733 1156 92 185 5…
Output: NO

Example 3:

Input: 322 922 67 75 152 112 103 166 244 94 197 149 124 143 59 271 26 182 114 105 66 128 24 282 290 190 96 23 85 277 249 309 285 308 186 48 273 141 230 61 7 230 107 207 55 315 93 270 155 29 58 32 100 194 245 54 298 85 66 148 21 149 239 307 7 319 5 216 70 83 83 204 259 279 228 153 108 282 242 33 29 63 271 52 180 296 194 245 113 177 261 223 245 21 283 46 3 280 99 25 21 102 46 35 87 200 281 187 115 175 251 273 248 61 22 272 202 187 292 29 65 40 152 255 312 104 260 141 82 270 296 145 131 126 43 172 126 245 258 120 264 95 37 39 227 136 266 144 104 61 302 127 35 289 68 33 141 11 197 59 316 23 298 112 239 286 147 32 141 295 124 191 163 50 157 133 191 17 202 107 32 91 250 105 69 256 57 196 74 132 19 65 169 50 5 114 125 49 234 35 205 271 157 128 8 193 218 46 38 124 97 177 8 278 25 66 241 281 280 122 137 3…
Output: YES

Constraints:

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

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