CT49929

Scribe's Verdant routes

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Caravans arrive at the beacon hill of Lantern Tor with crates of routes, and Scribe the registry keeper must account for every last one. 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 <= 2889; 0 <= m <= 2889.

Example 1:

Input: 1711 1139 187 1048 1388 270 979 181 876 318 1542 1009 877 1227 222 1301 865 1449 1173 408 1524 984 1051 1317 1406 1531 30 264 186 1149 1489 576 1166 1354 1290 1285 200 162 347 598 1179 1477 643 205 1684 881 391 308 542 525 167 1271 1226 924 248 145 890 404 450 1668 645 101 259 440 265 397 484 1478 1186 760 1509 571 145 1210 243 664 1281 192 944 1015 283 1406 1097 370 1129 1087 563 17 1234 11 1673 1574 5 1119 371 137 1707 274 1327 28 320 373 198 1372 194 363 607 1434 527 545 1406 307 87 901 531 1615 846 311 1585 1231 960 1491 1483 739 182 872 1554 1681 964 1202 922 24 1598 780 489 1106 672 1120 58 207 898 850 1238 1547 978 400 155 853 1382 1435 1673 381 1222 116 284 1114 685 1220 55 909 989 701 962 1630 448 692 964 1586 661 107 556 186 965 297 306 596 595 920 950 1518 996 1361 1640 1700 792…
Output: NO

Example 2:

Input: 1507 1388 711 326 1224 1289 584 1464 1302 800 1014 940 365 360 865 1121 672 1024 54 1156 1014 603 899 1435 1446 249 962 197 148 1356 836 199 1285 98 846 1122 1280 1174 440 1229 415 99 89 119 244 510 1112 793 1075 620 1470 41 638 732 400 569 941 1256 609 721 843 1464 418 1360 83 120 1445 666 1493 1 1194 1311 796 1500 217 1264 765 1009 471 1389 1025 169 1095 943 308 1053 718 811 684 899 200 1070 1246 613 849 850 1031 1451 1419 1478 554 890 744 1436 1145 998 1158 1167 179 172 710 127 150 1093 1484 533 617 568 331 1115 1485 996 671 1476 302 43 725 675 738 134 1406 1298 1008 1030 784 511 866 624 888 161 183 1285 1293 1001 122 468 924 1309 387 1317 217 1039 41 1045 1402 645 80 707 306 1246 1127 78 1172 1200 1185 398 1267 400 68 883 1273 766 141 1440 1176 221 690 531 1287 208 380 1472 409 685 141…
Output: YES

Example 3:

Input: 916 110 199 146 244 909 667 638 308 292 686 433 58 689 824 97 237 75 853 658 223 786 777 61 263 200 188 189 682 903 576 11 692 889 548 141 302 623 98 545 447 357 175 154 401 395 34 712 637 579 354 776 330 421 536 700 341 214 86 394 496 852 431 492 422 199 716 444 758 598 348 741 487 638 667 325 676 224 592 698 722 379 579 121 881 796 312 632 229 914 787 311 8 274 98 533 481 101 790 464 524 573 684 911 611 293 709 881 63 443 472 738 393 778 289 674 323 793 881 814 517 881 139 266 303 416 125 655 489 298 615 430 222 266 113 451 434 185 619 592 364 348 82 748 22 643 829 279 367 712 13 104 334 359 235 712 582 605 162 189 431 652 490 132 135 681 760 383 271 845 206 695 745 474 472 730 9 93 181 840 433 271 847 230 584 896 516 816 15 340 523 887 196 15 553 84 630 785 241 478 862 904 278 391 444 8…
Output: NO

Constraints:

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

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