CT35213

The Circular Route of Galeholm

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

In the zephyr cliffs of Galeholm, Miller the clerk keeps careful count of the corridors. Verify the safety inspections, every figure matters. 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 <= 3221; 0 <= m <= 3221.

Example 1:

Input: 989 544 621 776 304 573 296 184 967 178 73 915 338 928 582 882 591 753 708 322 563 226 823 593 241 963 613 338 969 195 217 313 295 116 43 504 121 101 665 948 168 552 645 196 465 471 891 969 14 605 78 291 863 230 222 714 476 638 449 435 475 501 836 99 351 912 322 189 822 79 660 578 880 658 492 982 619 625 313 227 561 5 939 930 443 739 736 448 283 320 198 527 741 259 539 731 287 950 641 215 478 365 365 661 73 954 99 190 605 326 515 761 771 646 241 428 741 110 257 615 546 769 533 884 170 623 158 100 864 174 322 244 32 468 67 1 521 412 265 184 716 371 593 955 931 335 264 778 24 620 447 698 474 539 836 124 166 231 275 141 620 159 447 869 597 137 311 515 924 209 243 946 160 10 808 95 71 18 483 523 383 804 714 280 553 497 15 779 448 801 818 729 944 575 431 514 491 127 572 554 654 703 150 188 533 …
Output: NO

Example 2:

Input: 3128 433 2093 1580 2759 2445 2216 66 3114 2099 801 1824 1696 3116 1370 2425 3053 1087 1336 685 101 2550 738 1460 2303 360 2355 479 1940 2350 1817 659 1228 655 2928 1515 769 569 2767 1887 1869 2124 212 103 2794 79 2816 573 2286 2742 368 955 441 575 1406 581 2872 1252 840 2222 1480 396 2582 1727 123 1552 1649 282 2537 2637 632 2482 2080 1557 8 325 1742 2362 1442 2688 1349 59 1489 2601 817 2699 2271 1014 1509 335 1840 1219 747 408 1067 2237 1116 2134 1667 835 2329 1762 2604 576 2300 810 1630 1421 1560 1875 1897 267 1779 1294 2096 1433 1208 1908 228 1474 1207 194 1839 1500 1240 1570 1493 369 2546 618 1121 1877 233 1561 2269 2913 1008 804 1690 1294 1066 2426 2587 3027 1667 1256 2806 2972 1729 361 1726 2216 119 61 2582 2214 2857 2659 1967 2572 1694 2157 2673 2479 562 1017 1391 2516 1239 2699 310…
Output: NO

Example 3:

Input: 622 253 143 407 483 170 505 21 524 226 547 54 453 333 352 77 387 216 107 440 227 306 388 552 615 190 274 580 197 114 49 566 418 553 82 1 15 503 288 531 275 59 354 431 483 209 241 346 535 606 11 78 221 298 448 63 408 247 349 390 498 66 528 162 311 595 318 11 380 604 458 408 521 440 96 218 100 561 391 61 275 177 166 372 177 508 143 393 306 265 601 196 463 269 369 151 504 579 591 31 8 119 12 588 120 504 178 417 495 429 621 267 45 36 35 237 477 137 104 23 326 404 400 334 253 590 235 9 273 178 504 604 299 362 554 9 40 15 56 133 75 312 480 94 450 550 571 622 248 52 534 346 343 242 557 447 126 613 32 5 533 575 239 363 241 289 417 370 413 206 335 539 332 247 64 329 488 189 292 369 45 458 613 195 232 489 67 499 514 342 147 68 275 14 34 618 285 20 456 227 380 258 197 4 215 493 12 266 362 51 98 101 5…
Output: NO

Constraints:

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

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