CT37208

The routes Circular Route Puzzle

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Zephyr runs the workshop at the old quarter of Brasshaven. Today the books show a list of routes, 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 <= 1690; 0 <= m <= 1690.

Example 1:

Input: 298 1629 151 185 46 65 170 244 253 37 39 11 13 226 227 260 81 195 116 295 254 120 264 19 54 152 44 64 297 255 69 20 110 293 157 145 192 38 86 177 274 154 72 148 98 120 71 168 30 29 50 143 205 43 197 273 2 26 46 253 70 262 57 72 50 136 272 97 99 117 21 257 49 75 73 156 78 12 176 293 261 108 124 184 43 262 124 89 159 172 279 75 82 227 187 80 209 23 241 31 297 292 37 93 241 29 136 94 55 46 109 177 16 180 273 119 22 218 269 138 255 180 200 252 117 100 20 273 182 192 89 110 48 161 268 205 116 201 192 11 177 145 25 274 263 87 110 101 40 163 250 147 107 64 64 261 50 53 236 164 206 210 162 124 11 175 269 205 236 108 282 5 16 66 228 113 3 258 12 5 142 28 178 185 103 36 36 253 262 208 151 288 280 44 163 9 44 68 177 222 222 121 176 139 69 90 283 224 286 153 44 106 132 289 226 109 276 77 178 159 1 183…
Output: YES

Example 2:

Input: 328 620 141 70 175 263 48 231 30 298 75 71 257 74 208 33 78 257 86 93 138 188 67 183 281 110 184 125 56 210 140 61 242 68 229 286 179 314 311 51 111 219 120 77 325 153 51 116 310 65 311 320 129 52 104 57 312 178 157 74 27 323 63 45 114 81 292 228 92 187 229 103 38 133 271 206 79 54 84 65 261 307 82 45 314 290 26 265 138 186 79 176 273 118 88 297 93 66 285 152 292 227 162 223 27 308 62 109 203 32 100 84 212 171 91 140 148 298 328 183 150 13 179 158 113 33 186 297 27 74 267 162 46 171 90 12 301 251 217 200 286 191 307 34 306 298 268 136 19 18 105 237 124 66 308 261 173 252 285 218 111 75 14 12 12 35 221 96 321 90 120 222 291 253 254 267 305 9 110 2 81 84 261 16 267 156 183 308 280 147 50 274 156 188 289 49 273 280 271 91 42 196 307 86 51 298 293 57 64 327 29 134 159 288 74 106 59 256 89 58 2…
Output: YES

Example 3:

Input: 1499 719 1284 424 832 1244 92 1205 357 888 488 893 177 463 121 1002 1053 976 1056 410 632 1463 1024 490 429 5 1365 40 597 1449 742 510 113 41 186 1378 308 1134 470 178 732 235 788 558 641 1462 1220 1300 934 1111 412 1091 1496 979 912 1384 802 166 99 692 1288 1087 267 768 1044 1219 482 145 10 695 1134 1168 1050 1172 52 454 1174 199 820 1111 806 427 528 378 1159 518 240 936 837 420 826 44 1145 492 964 49 1225 518 1462 367 976 815 711 218 1224 1038 1077 692 1233 50 214 634 37 62 344 548 773 201 954 399 1355 904 382 973 1023 347 206 195 1249 716 11 1472 222 593 568 194 746 535 1302 873 398 630 685 369 598 676 457 340 1251 212 923 241 613 411 85 1487 74 1029 1143 881 685 12 1440 734 167 112 1398 976 27 1357 602 16 1008 376 503 298 1401 1113 620 751 464 493 1286 1323 57 439 1140 363 754 1094 106…
Output: NO

Constraints:

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

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