CT48074

Iker and the Vermilion bridges

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

At the quartz ridge of Glimmerfell, Iker records each bridges in a worn leather ledger. The guild wants answers, not guesses. 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 <= 1518; 0 <= m <= 1518.

Example 1:

Input: 670 460 564 174 121 205 174 652 376 69 515 551 204 254 530 258 347 439 629 599 450 570 305 554 352 666 452 27 66 389 568 290 237 654 665 413 350 222 132 351 410 122 473 285 500 265 406 604 77 33 454 181 483 289 50 202 626 655 611 412 42 228 324 178 53 199 341 659 310 446 184 615 355 515 524 477 648 134 251 191 546 505 38 13 146 157 366 356 469 535 212 315 146 193 395 611 634 7 195 196 17 487 591 136 462 594 501 652 230 124 136 225 77 240 599 508 420 143 41 369 239 168 442 375 648 95 249 108 599 326 237 520 416 257 221 596 38 72 205 282 33 593 392 253 205 646 587 276 524 351 218 99 230 497 46 278 62 2 43 485 520 651 492 374 73 302 232 491 155 493 293 566 599 281 475 121 302 592 631 327 643 568 525 343 276 604 59 149 495 27 621 620 420 620 315 210 354 433 463 246 270 655 547 537 401 348 102 …
Output: NO

Example 2:

Input: 1075 592 588 537 80 573 687 716 598 977 708 809 176 847 247 213 18 980 72 582 224 147 1065 584 183 745 163 1059 907 176 646 567 242 1021 871 255 837 762 801 99 778 236 221 348 1052 400 206 551 773 231 343 406 122 881 603 823 636 1058 221 251 481 23 328 89 869 956 1053 9 454 856 721 396 907 685 831 908 1026 138 1065 712 971 590 332 644 778 35 684 851 535 124 975 305 532 822 697 397 7 788 72 912 840 386 199 910 424 913 489 527 898 618 153 168 748 984 550 98 803 1048 1025 696 321 358 275 150 1051 621 161 311 819 924 290 1048 597 1046 914 913 504 331 714 366 87 215 171 109 256 593 317 501 947 797 557 446 415 920 148 755 446 491 726 892 704 1041 345 570 159 241 806 399 53 212 908 551 878 647 445 622 1044 30 379 824 75 432 753 484 411 284 916 8 274 694 1055 1061 213 132 1061 380 582 743 219 635 …
Output: NO

Example 3:

Input: 353 1046 109 308 321 108 103 303 8 300 254 281 229 175 51 89 195 261 87 183 145 234 71 110 187 207 247 82 146 49 157 215 132 127 93 24 352 6 139 349 1 282 288 276 295 247 344 259 152 208 48 11 19 148 352 222 228 225 65 7 309 324 307 161 172 19 248 25 112 327 55 93 115 296 35 349 299 22 24 47 350 148 210 11 127 141 158 212 151 183 4 173 284 49 158 274 119 85 338 26 106 62 175 131 123 259 72 274 86 260 270 259 258 96 338 284 201 237 121 133 98 144 227 235 209 210 211 286 218 280 70 116 24 173 149 147 60 242 22 301 59 235 93 315 116 260 121 265 304 164 79 250 118 241 40 12 120 55 348 65 25 32 343 348 50 258 257 271 288 39 181 190 37 284 301 346 12 102 148 208 150 40 165 231 201 351 160 26 319 211 201 286 77 245 101 223 306 251 26 168 216 23 114 15 157 187 244 265 229 188 146 137 62 178 145 18…
Output: YES

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Iker and the Vermilion bridges - MEDIUM Coding Problem | CodeTikki