CT56562

Dante's Lazy Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Caravans arrive at the saffron fields of Marigold Row with crates of corridors, and Dante the chronicler must account for every last one. 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 <= 1557; 0 <= m <= 1557.

Example 1:

Input: 935 757 74 46 922 251 500 9 661 135 44 408 234 41 424 490 907 572 14 922 548 96 125 583 559 831 518 20 5 72 423 288 299 1 695 36 364 798 722 548 174 284 905 48 365 525 158 464 909 398 646 736 907 769 767 842 14 511 676 87 34 498 63 160 62 505 402 559 33 426 129 374 413 820 741 201 529 637 690 193 644 35 670 299 166 401 814 536 934 138 470 794 478 342 142 840 227 303 743 876 413 251 697 71 754 363 745 267 869 450 512 238 722 558 477 921 438 624 603 456 401 909 587 731 273 715 520 332 873 918 377 455 774 854 847 317 389 680 837 146 914 626 736 733 127 295 782 90 409 39 523 770 866 300 877 400 115 244 178 372 502 141 125 465 684 7 707 123 856 704 306 17 886 150 482 529 620 921 83 677 900 769 323 451 208 893 626 842 273 541 276 705 719 523 52 644 55 568 163 244 238 123 134 347 914 345 445 569 …
Output: NO

Example 2:

Input: 882 1529 730 38 53 529 824 109 340 601 822 792 135 85 713 373 294 695 116 160 364 462 479 850 602 247 637 481 466 563 800 428 48 708 281 730 161 538 412 110 153 682 728 252 317 380 314 63 21 758 381 91 822 267 855 62 855 616 63 871 806 627 705 592 830 242 579 494 870 338 376 231 151 882 405 629 472 346 675 166 83 607 30 748 594 378 226 670 832 336 19 438 480 846 157 868 362 555 154 855 584 67 648 385 68 548 23 102 607 587 571 111 705 144 829 49 525 120 107 355 516 363 789 452 767 455 291 593 658 516 656 333 852 364 599 306 427 633 204 724 539 764 877 775 772 880 799 148 519 129 697 389 474 689 706 611 700 732 606 559 358 279 81 683 8 103 660 136 65 598 647 740 356 721 676 114 829 137 783 214 728 233 565 539 660 381 674 391 192 111 285 580 818 153 819 522 330 868 401 26 865 411 376 456 392 …
Output: YES

Example 3:

Input: 349 155 34 87 54 329 251 195 213 79 275 165 315 225 82 101 164 82 325 82 307 215 50 11 5 204 218 315 13 104 182 88 179 339 184 3 239 297 130 220 210 88 266 333 294 338 133 70 110 146 293 174 259 71 38 244 45 281 141 305 208 267 135 136 305 288 335 211 104 259 59 290 140 306 327 313 277 36 128 231 102 9 262 197 309 220 247 310 44 182 22 220 187 284 151 33 152 70 134 155 254 261 220 186 231 173 205 2 126 175 19 173 28 338 302 277 258 299 236 132 168 96 330 71 311 101 257 300 132 55 169 138 220 183 109 62 101 21 221 343 72 49 287 38 144 109 303 209 60 210 39 265 11 103 265 28 46 170 313 118 330 59 76 240 199 324 286 300 57 93 271 340 265 76 26 88 121 133 21 291 93 297 16 120 196 343 319 102 202 106 233 202 236 317 345 132 70 212 26 221 330 331 268 265 134 115 337 96 294 325 5 306 260 323 105 …
Output: NO

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Dante's Lazy Ledger - MEDIUM Coding Problem | CodeTikki