CT52289

Esha and the Timeworn routes

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Esha found an old ledger of routes in the apiary attic at the cork grove of Barkhaven. The margin notes pose a precise question. 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 <= 1479; 0 <= m <= 1479.

Example 1:

Input: 373 104 32 52 205 47 138 18 205 66 185 223 333 361 188 350 277 209 82 3 150 157 328 285 103 197 303 49 168 343 265 129 104 351 172 247 55 294 207 135 140 92 232 148 221 111 371 345 200 108 55 31 63 113 93 16 133 66 74 110 121 99 226 290 317 341 200 188 288 87 35 158 266 1 223 112 189 47 27 82 234 4 259 206 208 232 253 325 93 328 217 291 367 133 143 174 266 139 171 217 52 221 194 281 70 344 146 142 315 5 88 236 350 275 325 225 72 20 70 249 112 248 372 200 243 261 169 87 152 76 174 341 159 120 20 150 171 275 284 63 218 8 46 325 9 1 308 339 92 268 227 164 209 296 324 278 346 99 138 193 120 307 132 61 78 288 346 155 100 176 324 314 298 370 75 130 26 262 37 236 45 172 371 358 295 344 254 30 25 237 329 365 134 250 153 114 150 109 351 27 84 69 102 283 354 125 147 25 373 1
Output: NO

Example 2:

Input: 382 1267 377 372 68 40 284 94 351 250 129 227 320 72 306 15 286 137 51 145 376 270 123 257 305 36 222 332 27 147 144 274 202 265 93 42 11 377 240 15 350 18 97 137 162 349 231 8 37 205 74 107 211 155 352 155 377 221 247 193 103 349 278 148 160 285 210 64 23 173 275 362 240 161 257 224 113 29 40 282 236 5 69 341 372 227 5 173 5 230 152 61 13 198 1 263 140 35 49 228 51 160 320 290 150 94 12 232 79 278 375 313 58 293 204 50 153 307 342 114 148 14 236 311 54 230 289 322 180 248 336 77 142 93 115 186 35 381 213 180 33 218 360 282 368 291 182 332 32 173 123 28 271 177 236 235 160 47 183 160 80 199 240 224 248 9 162 161 339 52 213 239 193 79 96 215 235 229 219 247 279 174 103 233 369 219 374 123 329 22 62 299 87 304 238 241 83 293 287 55 349 183 44 56 218 194 51 330 348 282 144 148 70 270 12 113 3…
Output: YES

Example 3:

Input: 455 882 233 128 210 250 276 253 343 126 151 92 245 368 251 218 50 387 347 123 371 110 36 275 428 61 377 167 249 13 374 244 246 22 83 189 340 91 336 163 42 448 400 271 382 193 90 209 373 158 120 433 38 233 300 283 271 209 212 318 321 259 71 38 436 100 11 40 357 42 391 297 344 17 210 417 68 352 335 23 200 316 421 170 445 248 178 414 251 40 349 308 168 213 357 190 107 403 357 125 63 32 104 136 362 190 393 17 37 398 147 258 361 386 434 448 100 367 88 453 276 49 199 34 429 22 453 385 112 448 316 220 12 64 380 267 15 200 136 313 263 13 451 142 364 3 229 357 101 16 169 245 18 324 453 130 401 19 132 364 352 305 299 282 41 123 40 310 328 454 136 351 280 220 421 59 146 280 305 183 328 81 203 197 62 433 387 415 202 268 122 271 56 275 362 323 255 208 210 37 215 401 191 266 55 144 185 39 119 283 72 43 …
Output: YES

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Esha and the Timeworn routes - MEDIUM Coding Problem | CodeTikki