CT49702

Tanya's Circular Route Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

It is audit day at the zephyr cliffs of Galeholm. Tanya spreads the routes records across the table and picks up a sharp pencil. 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 <= 1813; 0 <= m <= 1813.

Example 1:

Input: 171 1779 144 60 20 48 68 151 97 19 74 28 88 126 153 45 18 162 150 27 158 50 156 24 3 170 139 51 64 84 113 46 82 155 154 136 153 163 112 48 169 99 68 38 60 155 3 72 34 86 112 37 114 153 118 95 64 95 167 153 114 166 128 22 89 149 20 154 17 114 138 49 8 140 101 40 138 59 20 158 13 106 129 78 12 147 65 37 98 101 41 3 90 22 134 149 85 73 74 140 44 51 89 130 59 14 41 126 87 90 17 4 35 156 95 55 2 107 48 27 29 57 126 85 16 146 96 16 89 94 156 78 121 25 71 157 64 135 132 25 44 140 137 102 138 145 128 92 55 6 43 109 156 123 159 78 66 8 63 132 166 57 6 54 45 115 35 98 141 81 164 83 16 129 82 42 169 95 7 142 76 63 79 8 85 44 157 14 78 18 154 110 129 148 3 124 26 120 108 124 5 61 62 35 22 92 129 33 170 36 40 1 163 167 23 35 124 68 83 96 108 99 5 159 2 39 53 100 142 12 57 30 52 93 40 82 20 71 47 154 15…
Output: YES

Example 2:

Input: 789 112 2 463 534 648 334 113 765 542 639 149 766 748 526 581 653 586 750 587 320 312 722 344 217 476 268 46 416 367 610 243 545 56 258 94 722 730 504 496 485 126 366 197 751 644 397 496 283 573 41 96 238 654 330 117 450 480 427 12 110 160 189 466 132 344 677 687 256 325 717 297 448 584 713 619 671 396 514 113 566 737 106 218 484 82 666 706 180 752 481 778 362 712 239 641 422 139 694 564 501 128 724 9 152 51 469 403 403 143 714 292 393 463 138 534 726 690 588 546 84 66 742 284 719 71 434 60 75 44 423 429 305 299 645 594 690 696 303 54 258 735 780 522 93 2 354 230 643 757 121 611 205 322 244 609 443 535 566 135 199 381 653 60 517 98 88 438 537 771 412 360 454 226 39 766 466 203 448 122 671 123 212 369 101 515 260 388 558 385 636 350 478 88 510 357 231 564 762 136 422 157 618 61 38 718 13 20…
Output: NO

Example 3:

Input: 1453 945 1340 174 832 1135 682 125 1382 1136 817 526 146 669 346 1413 111 1008 668 547 378 838 354 1428 569 401 1054 1269 760 405 1183 1016 627 651 1393 424 423 1065 353 622 123 7 159 603 1152 774 776 1012 757 1071 936 803 161 1024 1347 320 997 915 862 1028 325 1263 330 1084 22 334 860 355 300 636 808 927 369 1324 371 132 257 999 412 194 1128 1269 891 1035 848 1088 153 53 1226 536 898 24 492 60 1155 660 278 1351 483 1237 1424 1411 379 438 1405 15 21 959 660 50 1058 827 1079 511 320 138 852 180 246 399 467 1272 586 134 1151 451 1444 702 825 1178 505 1304 203 630 57 1202 1339 1398 860 1041 1219 657 52 37 1352 218 748 1240 226 151 301 1057 977 541 353 907 230 622 979 963 431 156 1451 1297 10 514 363 103 106 1041 1011 560 246 1219 589 142 324 1241 168 836 1180 876 809 462 1238 442 194 33 327 1…
Output: YES

Constraints:

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

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