CT51315

Sarla's Circular Route Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The auditor Sarla has been asked to file the annual report. 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 <= 1131; 0 <= m <= 1131.

Example 1:

Input: 1105 761 168 902 561 764 69 893 319 964 759 250 754 46 866 157 333 1040 906 790 976 368 948 388 678 285 550 504 1014 218 564 136 455 108 985 1055 679 58 483 203 862 946 1018 1080 134 470 272 231 2 1060 441 4 157 486 799 312 487 820 327 500 825 913 208 18 791 906 758 553 552 36 350 155 854 775 181 723 910 231 759 938 1095 821 427 749 253 588 213 298 898 541 11 258 231 527 998 81 658 887 75 717 1096 1042 813 956 903 990 487 357 1038 1035 1081 1069 1000 517 944 35 1035 67 279 751 867 58 574 545 869 419 746 661 253 260 617 472 493 21 452 551 466 321 915 486 136 661 480 1093 968 123 244 874 616 707 27 515 769 258 466 575 551 45 986 153 255 240 1034 142 882 110 523 197 793 504 935 588 246 1047 39 773 195 920 675 143 465 496 664 1048 628 531 945 62 773 132 123 162 829 3 561 765 1068 852 1020 767 …
Output: NO

Example 2:

Input: 495 406 229 418 131 184 131 430 72 90 147 5 482 432 345 211 488 34 22 222 61 166 124 445 45 391 202 28 140 311 159 360 59 1 31 345 449 481 492 109 304 164 483 198 464 299 17 408 319 322 35 454 161 190 219 64 480 287 452 255 198 318 370 243 168 255 239 79 178 456 45 52 177 156 390 345 87 460 11 377 272 239 352 290 80 312 402 55 106 84 346 305 276 229 421 282 357 368 260 160 35 163 22 43 31 294 157 91 149 423 412 153 404 144 90 153 448 320 438 116 375 192 477 424 266 94 473 253 364 111 346 169 392 371 181 66 24 173 405 44 367 49 24 66 340 346 445 231 485 434 265 292 446 265 347 20 135 259 49 222 136 91 448 13 339 475 133 100 75 16 426 375 428 9 469 313 422 357 252 36 38 482 374 202 353 104 254 126 140 170 181 194 427 168 7 137 85 479 448 260 438 435 4 304 320 174 168 106 381 354 276 132 221 …
Output: YES

Example 3:

Input: 967 471 492 517 864 116 661 490 82 498 413 918 476 409 383 224 689 86 683 869 30 769 602 185 336 414 204 797 118 266 145 266 240 333 19 601 443 299 535 405 238 330 517 737 849 69 265 93 779 933 936 706 270 941 52 963 611 381 539 308 760 163 439 349 243 126 361 375 325 133 851 762 13 142 61 34 176 539 67 813 609 562 168 726 284 550 791 47 402 823 333 202 509 579 314 411 739 747 396 431 879 598 176 794 663 254 773 253 625 685 885 628 857 512 25 535 89 795 73 337 568 160 880 818 865 596 93 595 922 501 193 864 66 138 800 655 549 866 449 955 680 965 668 767 577 312 731 112 5 513 723 306 431 46 706 165 413 751 636 833 781 817 698 263 580 602 743 283 157 807 447 646 607 457 319 561 288 178 764 173 110 667 737 171 672 604 628 900 469 674 112 197 406 375 65 444 35 457 105 677 886 97 720 117 492 806…
Output: NO

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Sarla's Circular Route Ledger - MEDIUM Coding Problem | CodeTikki