CT47593

The Dusky Circular Route

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Hans runs the mill at the shipyard of Keelwind. Today the books show a list of canals, 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 <= 1679; 0 <= m <= 1679.

Example 1:

Input: 157 833 85 100 131 87 61 143 135 151 75 87 81 95 92 139 3 79 103 33 80 35 29 9 46 12 62 98 128 125 101 76 33 108 124 20 61 113 156 65 157 3 35 121 41 29 157 139 47 147 128 81 35 57 35 95 4 52 147 58 20 151 154 40 132 83 88 69 77 53 74 37 42 67 42 39 136 104 88 67 111 7 141 8 134 50 98 147 84 132 5 45 13 79 15 143 124 151 76 99 27 81 22 70 14 84 91 2 12 88 139 19 99 52 122 109 50 63 124 152 30 128 5 96 144 76 80 41 126 146 44 4 133 20 121 40 133 22 97 22 145 44 140 123 145 85 83 48 121 84 23 152 140 64 102 123 35 133 125 113 82 27 125 62 83 93 61 46 98 9 118 17 97 63 15 151 134 18 19 115 136 102 111 62 141 100 28 115 121 111 129 118 131 62 90 64 110 109 37 112 4 27 66 92 80 4 151 145 139 141 54 22 141 123 66 61 152 66 103 40 124 91 15 57 97 9 94 45 103 102 109 85 104 137 10 38 128 155 108 2…
Output: YES

Example 2:

Input: 1459 1028 984 582 506 963 540 291 863 626 266 1449 364 296 515 989 730 252 1150 471 504 546 1403 1056 948 1095 168 560 71 423 1253 1413 1436 96 1452 1223 330 1293 688 273 239 1038 288 1327 600 1397 494 25 1407 462 1170 789 711 1306 311 308 567 79 283 1130 232 152 1363 650 369 180 640 458 1367 66 553 1208 1156 1246 781 687 68 465 25 1246 418 1059 559 471 660 423 617 870 323 503 1069 172 893 300 1228 1198 1235 1385 841 942 74 242 944 130 302 411 26 823 1173 1124 1187 1174 832 234 469 1083 242 157 706 257 1180 1365 871 1418 1116 1255 1372 1076 1020 395 472 1143 844 1196 688 135 273 1270 1350 95 932 711 862 878 68 1397 1211 611 903 70 1241 1371 1379 292 1072 721 1197 1037 966 377 1408 984 972 1457 764 1070 601 426 717 1000 1304 1085 1447 1360 815 135 166 515 1184 606 1456 959 930 673 539 1246 …
Output: NO

Example 3:

Input: 416 1352 3 23 143 117 385 228 29 413 321 172 298 278 75 50 121 231 253 353 162 239 204 251 64 258 369 264 412 316 323 349 65 276 124 72 396 178 352 178 167 90 331 334 189 241 132 297 4 10 216 195 334 276 406 298 375 259 96 371 63 207 148 129 384 371 38 396 169 89 49 133 227 153 287 344 218 247 402 93 20 283 157 251 400 257 165 265 320 344 303 138 252 269 115 27 375 71 155 312 115 399 10 176 192 4 372 338 154 205 79 407 82 216 111 183 390 242 177 98 65 294 241 69 359 174 322 305 243 164 153 132 126 283 223 94 80 146 171 355 341 286 152 216 390 270 250 124 290 374 284 8 12 323 197 256 267 385 254 158 89 115 117 18 172 291 360 388 332 80 386 142 233 316 169 374 3 174 30 290 312 38 111 280 163 270 264 139 247 185 376 126 259 117 405 246 124 325 370 181 123 194 298 280 198 271 146 228 323 320 3…
Output: YES

Constraints:

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

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