CT56353

The Circular Route at Sleekwater

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Varun runs the bakery at the otter slides of Sleekwater. Today the books show a list of corridors, and the numbers must be worked out before sundown. 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 <= 3601; 0 <= m <= 3601.

Example 1:

Input: 3464 3408 179 164 3372 1487 2213 2179 348 864 16 2170 2521 2162 1479 2172 930 3138 2829 91 2578 3157 355 3234 2920 118 67 554 1585 844 1484 2361 2339 2742 2950 1022 2868 2642 36 990 802 2992 2618 2145 1093 999 435 3064 1766 1811 1852 571 2033 1740 1445 1801 577 1017 788 13 3068 2706 1737 2972 1644 2238 2857 1482 686 2018 1065 143 2794 339 1283 1713 1015 2961 603 1480 2172 1591 587 2072 1398 2604 3005 2010 1639 221 1380 743 3111 3344 1015 8 3438 419 1272 1315 477 2422 2714 1721 2502 721 857 3203 2841 2426 3314 900 2288 2704 732 3261 1167 178 2038 475 1554 1677 899 2557 3396 2003 1974 544 3352 2930 1607 427 2504 3367 1311 334 2061 106 3220 1788 2167 2256 561 3042 2890 2479 1132 1267 706 1599 1712 402 3426 575 2596 929 2139 948 819 2567 672 3138 2299 1916 1582 170 2779 719 2968 1048 2543 125 …
Output: YES

Example 2:

Input: 187 2921 131 128 105 176 37 16 73 27 90 88 113 174 76 22 109 84 116 8 123 45 7 32 50 132 125 134 110 88 140 7 24 113 111 156 124 103 167 46 179 51 119 61 97 62 15 13 164 160 28 168 71 121 110 151 104 130 1 166 114 175 100 98 110 143 133 86 75 66 67 155 72 175 25 84 34 13 14 158 73 19 146 28 23 51 6 108 56 1 175 111 109 6 162 170 82 121 85 59 100 48 98 32 88 138 30 23 129 145 176 155 131 29 37 116 133 107 175 29 136 106 102 171 16 163 103 122 16 141 7 16 94 10 42 97 120 105 20 184 51 164 86 63 4 182 32 147 131 25 165 38 186 130 177 17 182 116 115 148 162 11 116 26 14 9 50 78 187 155 58 140 159 35 12 118 94 130 3 52 167 38 68 148 21 150 116 39 49 59 5 153 37 72 27 66 118 39 29 150 180 119 43 107 96 71 106 124 182 153 73 5 153 70 140 123 143 32 83 7 96 58 114 88 178 183 22 166 10 45 90 85 105…
Output: YES

Example 3:

Input: 3546 701 3139 2758 670 635 3276 1961 3144 2844 1343 2192 1709 1212 894 478 2894 1104 1605 2376 3336 793 508 1990 1371 2152 1884 2500 1160 1610 1438 2236 2784 1794 2986 1018 804 1633 1776 1896 2782 173 2247 855 1679 2777 334 2425 3171 1103 2566 334 561 3244 2788 1249 1504 1382 2403 1589 2936 2138 869 1621 2699 1251 1845 1814 579 462 1747 2052 2824 1225 1664 1895 1311 667 1936 2080 1531 2010 3449 221 960 490 2245 2052 3461 1979 2659 1589 1013 257 632 329 30 1034 2295 1487 253 784 1088 310 2953 1373 1682 535 1874 695 449 240 375 3541 2607 970 2428 647 3334 3062 2849 2339 1652 673 138 2452 1973 2771 3004 2126 653 521 2752 1272 3234 3185 1843 1568 3046 861 2492 2786 1706 1248 662 2616 248 905 2935 1417 405 2389 985 2832 707 2438 3346 1178 522 24 2031 63 79 2471 1600 3154 9 2678 3089 2384 1220 1…
Output: NO

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Circular Route at Sleekwater - MEDIUM Coding Problem | CodeTikki