CT48400

Sahil and the Circular Route

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The factor Sahil has been asked to catalog the new acquisitions. On the desk lies a long table of corridors 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 <= 1305; 0 <= m <= 1305.

Example 1:

Input: 1018 65 798 717 607 330 408 564 885 24 793 440 686 931 824 135 610 677 336 638 885 910 566 217 725 2 370 555 948 236 594 29 468 158 173 844 305 619 3 620 256 593 287 66 970 247 676 896 896 131 555 530 529 848 432 706 785 933 835 130 452 25 43 1016 767 667 308 331 669 56 504 456 392 39 916 62 106 369 386 18 776 401 590 389 114 550 478 173 258 495 498 919 657 526 691 611 736 445 73 807 661 428 960 845 817 855 719 65 764 194 344 810 720 271 642 569 945 340 664 519 256 467 773 116 498 889 698 100 548 647 442 214
Output: NO

Example 2:

Input: 639 885 180 477 56 117 378 192 80 398 261 68 317 316 241 581 530 534 316 322 73 191 219 535 475 241 281 207 240 312 191 534 453 99 357 323 262 571 485 439 204 243 570 568 444 422 569 241 255 252 107 577 48 363 48 454 269 129 269 346 150 32 90 562 468 542 421 193 584 257 432 592 566 375 56 609 467 579 620 158 61 380 493 559 334 532 267 115 628 570 506 450 571 364 522 639 257 302 123 330 605 122 510 317 558 214 611 113 545 360 212 150 599 20 26 387 501 238 198 525 9 497 211 627 401 19 365 68 559 81 231 507 67 326 518 639 445 485 431 604 437 548 161 247 9 128 281 417 96 500 218 108 234 432 330 159 429 349 313 162 64 219 172 577 606 613 364 586 118 563 322 194 619 157 91 3 626 142 283 368 253 270 180 355 319 404 301 139 284 324 199 506 161 140 496 169 575 597 601 534 108 369 137 131 522 79 228…
Output: YES

Example 3:

Input: 780 643 607 268 254 199 105 531 395 726 675 678 80 161 332 458 717 547 543 611 641 751 496 672 178 229 611 628 651 275 277 426 474 42 352 122 133 725 149 525 258 570 219 132 209 720 167 780 26 455 389 142 668 617 98 172 672 397 581 399 208 406 168 27 131 64 474 68 31 704 564 362 756 215 43 79 652 651 262 527 183 292 728 54 491 339 763 69 593 114 206 533 529 426 60 356 729 767 206 341 306 656 43 636 512 19 187 453 380 8 290 584 313 244 728 697 562 723 635 714 257 747 593 131 598 634 452 721 466 577 622 693 499 349 437 86 627 141 231 567 606 248 469 420 309 379 379 486 646 44 132 494 356 232 84 169 276 770 167 584 639 208 581 573 325 40 138 327 674 334 230 74 131 310 492 612 81 714 271 752 411 519 244 547 45 244 706 160 141 254 601 253 367 616 311 665 328 576 458 171 13 384 779 668 97 385 47…
Output: YES

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Sahil and the Circular Route - MEDIUM Coding Problem | CodeTikki