CT51685

Seth's roads Circular Route

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Deep in the saffron fields of Marigold Row, Seth studies rows of roads entries. One clean number will settle the guild's oldest argument. 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 <= 1897; 0 <= m <= 1897.

Example 1:

Input: 1802 17 856 1623 801 33 724 1136 1491 1151 985 444 451 406 171 1139 1156 878 1112 913 388 1738 39 564 1443 1419 1330 464 1026 25 1607 252 1799 1283 230 1772
Output: NO

Example 2:

Input: 797 1118 311 784 163 730 678 629 104 131 58 726 644 698 292 414 631 13 386 243 203 514 722 457 198 427 260 754 717 265 664 290 200 458 578 94 669 240 413 193 710 795 465 532 327 501 95 501 188 578 745 137 691 105 309 468 292 460 766 423 538 89 234 509 64 646 745 61 356 326 61 348 659 500 398 465 250 514 241 3 250 700 47 651 212 320 58 782 15 343 375 159 596 108 597 470 752 313 714 508 130 119 55 248 591 146 84 141 497 443 594 459 141 651 320 645 461 505 527 373 258 210 44 653 292 427 575 595 93 227 506 610 459 396 103 372 754 331 390 193 756 562 782 86 173 522 386 490 282 700 42 606 600 47 397 135 107 611 677 99 38 160 635 776 185 604 623 536 16 90 280 760 81 514 582 368 276 205 263 646 480 438 218 199 703 701 40 461 666 26 601 438 727 32 661 58 350 115 599 65 391 261 442 337 259 641 155 2…
Output: YES

Example 3:

Input: 486 1343 460 206 367 11 69 370 436 42 292 467 207 190 285 456 52 252 39 454 16 127 302 317 81 27 330 293 196 380 88 475 349 263 81 444 420 460 428 4 267 234 77 284 453 319 476 349 305 11 245 20 258 50 35 428 51 60 70 258 117 31 153 189 361 42 159 165 39 313 314 261 170 312 134 288 452 173 126 275 97 374 51 381 413 486 436 9 328 253 220 97 217 320 85 228 388 163 10 397 46 444 422 363 211 318 28 117 177 67 370 294 204 297 455 203 377 342 138 285 102 304 339 246 326 340 386 94 229 474 102 442 108 130 335 320 361 255 195 148 416 300 425 431 468 153 433 66 379 176 368 366 192 11 412 423 263 282 217 102 22 330 192 434 207 235 173 30 224 350 107 241 292 459 84 336 379 292 102 383 276 266 71 313 303 324 137 161 55 171 132 369 282 459 125 155 84 382 249 204 88 217 100 388 176 118 31 287 445 199 343…
Output: YES

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Seth's roads Circular Route - MEDIUM Coding Problem | CodeTikki