CT47726

Last routes of Jace

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Jace inherited the apothecary at the herring shoals of Silverfin along with its curious bookkeeping system for routes. Time to make sense of it. 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 <= 1289; 0 <= m <= 1289.

Example 1:

Input: 625 1046 521 589 364 150 242 533 445 518 318 539 559 230 575 359 20 302 10 524 423 483 534 106 340 348 21 18 89 253 514 487 103 150 209 419 120 602 56 158 14 20 146 577 456 59 129 271 568 198 307 245 29 38 574 124 25 530 300 31 321 146 387 182 465 245 300 594 176 259 177 593 600 541 356 349 238 68 321 602 61 4 608 598 77 541 412 276 363 95 270 160 241 71 93 400 574 184 253 479 36 311 34 290 468 544 420 567 411 301 338 205 598 607 256 188 369 143 334 17 88 40 114 335 391 211 258 226 563 550 123 412 476 440 268 428 157 427 272 139 9 574 377 92 519 284 396 316 330 220 429 263 39 217 539 239 424 399 160 242 279 104 518 399 35 541 376 472 211 21 558 57 301 83 381 223 518 8 258 602 65 515 518 33 515 245 456 119 243 619 388 166 435 87 523 72 38 558 239 280 290 78 508 522 15 159 398 386 38 271 369…
Output: YES

Example 2:

Input: 1231 1227 279 197 1218 635 733 342 444 64 507 875 244 193 42 400 352 934 1011 987 713 267 1066 343 516 492 1187 993 1121 563 1144 838 985 165 124 560 559 1079 382 530 1103 630 864 1209 672 703 1099 378 1121 201 252 792 619 1166 512 1189 1195 946 1230 623 522 793 521 1126 106 402 507 393 253 1066 403 104 794 621 1004 1231 126 336 185 1092 518 244 1198 410 438 1125 924 939 557 492 221 1021 138 133 757 742 532 348 1087 1153 407 203 590 281 552 733 641 1110 1047 1177 98 62 782 248 256 1051 186 649 147 393 290 1134 358 1118 202 218 351 760 771 492 418 694 649 463 663 642 797 102 792 1182 288 972 88 888 958 1054 554 1131 995 381 795 227 129 503 1075 746 1096 197 38 1034 1132 145 217 267 850 195 822 633 574 647 487 616 563 406 84 1034 188 880 318 387 1212 579 201 920 112 1109 424 524 7 1064 568 1…
Output: YES

Example 3:

Input: 977 496 787 369 36 343 758 110 478 793 661 629 662 31 295 796 734 304 185 773 231 80 282 399 734 250 95 229 551 135 825 881 97 398 32 330 707 220 715 383 335 354 584 249 12 122 225 322 444 686 390 231 61 736 942 210 775 503 138 773 81 758 868 194 822 409 699 45 729 863 438 29 432 311 605 32 339 579 920 751 749 371 760 413 398 428 213 220 776 356 328 96 410 482 148 323 394 121 65 968 501 15 922 927 361 530 153 213 684 517 755 393 718 822 361 470 108 963 11 140 361 284 925 34 885 383 692 126 20 500 529 107 465 953 657 257 933 429 614 593 421 577 454 19 501 729 98 392 958 877 967 759 648 389 947 862 352 401 233 713 377 968 404 945 181 640 606 766 306 277 155 383 903 438 177 479 138 485 631 17 213 65 26 176 325 962 604 570 625 899 26 357 657 944 909 908 725 732 612 893 433 308 380 651 942 132 …
Output: NO

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Last routes of Jace - MEDIUM Coding Problem | CodeTikki