CT40173

The Circular Route of the Mossy routes

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Chandler inherited the lighthouse at the obsidian flows of Blackglass along with its curious bookkeeping system for routes. Time to make sense of it. 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 <= 3029; 0 <= m <= 3029.

Example 1:

Input: 1327 43 34 362 554 109 1155 67 1070 1073 1287 267 705 1230 1261 430 1244 279 931 492 780 894 112 96 557 968 1081 1068 1151 416 186 1151 191 2 734 43 829 46 985 986 694 28 500 210 1184 621 898 1139 109 1155 566 176 337 316 725 328 597 74 370 538 909 809 189 1093 812 871 1141 60 357 178 1271 415 335 1275 134 266 758 51 1125 630 720 879 687 837 794 1323 333 15
Output: NO

Example 2:

Input: 173 2206 121 12 19 112 36 71 25 97 85 91 100 121 69 7 97 68 148 81 83 151 10 112 96 51 173 104 118 7 171 57 78 50 24 9 46 4 99 119 143 138 42 60 93 19 35 147 161 120 43 158 40 106 37 171 71 36 147 166 115 12 81 108 165 92 132 14 10 38 8 70 10 9 36 136 59 50 132 131 3 55 25 121 59 20 154 115 171 134 102 26 155 104 171 167 100 36 24 152 127 109 70 34 54 127 7 172 100 45 38 130 50 8 2 142 173 33 41 62 27 4 53 63 73 99 164 19 79 26 106 90 156 46 107 45 53 17 162 24 15 18 138 111 132 52 133 84 104 90 154 54 162 89 75 129 80 16 127 158 159 164 96 116 38 66 116 120 93 87 89 128 66 152 6 47 2 98 167 40 1 55 32 51 153 109 104 119 9 162 90 8 25 35 142 1 17 123 111 172 120 142 106 133 53 31 46 55 164 3 151 67 173 38 61 24 16 144 121 59 78 49 35 117 166 111 59 142 45 97 4 86 90 67 100 41 36 166 72 168…
Output: YES

Example 3:

Input: 1395 2640 26 1325 103 175 223 80 519 267 1042 1322 437 17 1252 1289 269 1360 203 1262 1151 1328 164 904 639 739 1106 483 656 709 257 434 9 1263 1264 905 377 1230 878 426 187 299 108 686 309 732 340 1255 687 992 619 1062 1058 43 1266 393 899 1131 871 111 992 305 401 1298 548 779 167 259 1045 729 220 763 1026 947 433 355 1012 370 23 355 81 301 109 723 831 712 406 151 883 673 760 117 45 407 25 22 1295 176 538 457 577 1330 854 121 1336 866 1370 275 703 1243 696 200 901 348 1221 888 1069 662 483 727 423 880 68 1038 637 92 65 1277 352 404 930 926 886 124 893 654 878 327 926 1164 1363 529 460 783 646 248 820 984 1198 693 1144 988 1274 1025 1367 182 219 1319 810 573 840 1112 526 1163 899 1239 1290 59 1202 961 268 1146 948 494 958 188 1280 597 1007 203 679 797 1220 240 1079 1 853 578 111 54 191 210…
Output: YES

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Circular Route of the Mossy routes - MEDIUM Coding Problem | CodeTikki