CT43378

The Cindercrag Circular Route

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The council of the ember mines of Cindercrag pays by the answer, and Sara intends to earn it. First: the full register of roads. 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 <= 1523; 0 <= m <= 1523.

Example 1:

Input: 1145 228 6 604 178 218 396 498 783 790 180 1050 592 158 613 395 1111 271 824 1096 900 496 947 950 995 568 1037 942 544 114 397 1043 845 159 1030 457 739 179 971 1101 957 60 458 982 277 447 64 766 639 788 362 233 1097 987 268 411 776 42 708 361 345 213 347 755 171 29 663 539 69 1023 683 207 718 290 944 1039 127 478 804 857 159 131 393 519 677 670 800 731 799 806 861 794 2 89 136 275 581 632 796 975 668 460 315 887 576 609 678 1091 127 763 906 57 1109 667 82 450 41 1081 775 421 113 182 588 239 648 786 883 767 259 136 244 417 905 869 218 38 232 901 217 519 331 713 477 925 628 916 200 557 682 408 1073 1060 733 1093 423 635 294 656 2 43 1071 653 806 956 960 173 138 314 25 896 356 1028 6 894 46 495 728 3 562 495 718 1118 795 822 912 111 119 234 204 1009 319 926 529 13 232 465 1100 587 65 512 83 …
Output: NO

Example 2:

Input: 1156 1145 272 91 648 944 778 853 592 179 87 681 485 784 200 664 343 1130 535 769 648 54 92 648 109 1034 306 541 858 444 521 787 51 151 377 593 414 1011 399 665 704 234 211 35 317 276 934 810 872 22 273 760 38 463 135 1055 760 25 213 274 1067 677 795 756 252 975 18 1061 1035 519 533 164 1139 712 797 1091 670 862 373 504 319 1010 328 1075 1073 811 839 821 581 898 1003 1081 294 95 507 237 930 603 372 160 355 416 593 341 377 865 983 653 130 1008 1022 34 1153 149 277 1048 894 973 655 298 370 641 992 80 145 136 137 97 275 412 619 539 587 336 278 84 1114 1047 735 440 996 935 203 947 1044 494 1118 113 528 1067 978 193 714 423 1129 989 487 1109 360 725 876 241 150 1031 21 572 402 128 829 752 418 908 459 196 440 232 290 614 584 337 622 139 483 75 147 1122 657 887 837 596 809 403 1121 563 559 136 751…
Output: YES

Example 3:

Input: 573 683 217 198 206 518 553 10 166 38 211 55 509 411 301 232 249 344 14 287 193 10 280 506 161 423 290 537 440 349 148 443 137 78 29 191 57 243 163 236 73 392 192 394 123 553 17 7 60 430 62 387 287 546 141 493 500 483 157 74 499 468 559 74 330 166 512 127 498 99 40 207 76 3 510 559 19 519 23 287 156 195 422 389 566 311 27 530 164 171 340 111 455 531 455 35 520 53 212 238 282 260 290 196 188 58 242 430 495 551 557 318 527 479 134 32 537 396 524 272 189 282 92 323 502 209 478 137 432 55 258 555 70 481 173 461 267 247 318 277 344 242 400 557 250 570 503 472 523 561 27 65 188 299 421 563 76 130 567 511 361 2 438 393 190 11 83 67 354 436 137 400 189 518 342 244 562 259 262 163 366 33 456 467 55 317 310 123 165 246 97 295 193 31 463 11 61 459 397 419 382 168 123 354 403 468 198 564 218 436 85 44…
Output: YES

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.