CT50891

The canals at Saffronia

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Morning light hits the spice bazaar of Saffronia as Yash unrolls the day's manifest of canals. The tally will decide the next shipment. 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 <= 2566; 0 <= m <= 2566.

Example 1:

Input: 845 2244 207 511 95 588 573 613 301 586 654 309 310 102 425 555 816 526 833 550 829 9 84 534 495 815 521 660 442 371 295 807 319 74 62 431 266 238 130 198 362 268 644 664 132 597 96 142 186 780 388 446 18 416 18 544 768 599 828 56 763 251 199 16 279 612 93 525 374 111 657 677 754 273 558 618 607 322 673 302 790 433 347 13 586 345 338 738 701 542 154 202 344 650 659 573 397 164 45 71 570 797 284 420 261 502 437 670 492 146 514 154 832 569 462 499 167 245 87 263 750 593 463 163 5 372 465 528 499 822 504 710 393 44 784 535 634 70 302 211 43 630 190 474 506 457 722 482 178 39 528 791 646 471 246 168 219 696 749 223 132 754 474 453 170 351 637 50 187 263 187 118 633 598 652 89 639 724 387 459 592 299 210 273 360 283 16 52 800 792 748 52 475 165 667 824 321 557 4 426 225 216 350 687 316 86 823 5…
Output: YES

Example 2:

Input: 1688 928 183 733 307 589 1001 897 454 747 1119 1011 1548 429 489 301 1558 38 1100 538 830 1313 429 40 855 1659 1084 943 1559 984 1033 168 4 1412 745 1183 702 1287 890 383 606 429 30 736 702 7 1445 523 1373 914 1639 942 1421 456 60 1512 1326 1343 721 118 180 531 913 1065 1349 692 404 268 139 733 1652 404 528 392 410 79 405 703 1341 230 542 750 1348 487 938 936 705 808 1356 92 563 1500 885 785 318 1417 256 1498 1445 620 884 128 407 762 1661 1407 271 1021 1307 20 561 1207 1568 1313 591 371 1171 1550 26 761 907 686 19 23 302 1351 1491 168 1591 893 902 721 487 1451 941 418 1445 441 196 1161 921 363 885 1102 758 940 1316 526 1134 397 1274 883 1383 811 1347 1126 235 81 1678 1300 1088 237 111 289 1641 626 1233 261 685 1579 177 307 222 1009 156 1331 1647 138 1476 1033 828 1023 245 543 60 1165 444 1…
Output: YES

Example 3:

Input: 1999 327 719 939 833 913 1971 905 1821 965 735 46 897 1641 26 423 1848 889 91 602 1585 1142 27 103 193 1239 315 958 7 1198 133 668 1613 1120 470 482 1463 1204 1435 1978 568 498 333 1617 1709 1679 795 747 871 39 1785 1544 449 1110 1085 625 1120 1846 585 1055 237 1139 674 899 1368 365 264 1342 701 920 414 101 1028 1375 1027 594 1604 588 698 1489 345 1297 65 487 294 1590 739 1711 1674 840 1252 860 660 1880 229 1415 1014 1659 439 1834 1282 1746 262 1589 1311 138 1183 977 1105 1988 1285 856 577 1737 1023 732 1874 572 1371 1338 1431 15 374 965 615 1525 799 1278 1140 1776 761 237 186 207 1394 1153 1131 379 1983 1538 1634 910 1043 1032 1717 1171 1889 167 1308 1424 334 1406 433 1477 713 1676 1363 1590 1598 1160 1386 852 188 1244 552 758 896 965 1547 1040 644 908 1753 116 661 717 544 925 433 835 16 …
Output: NO

Constraints:

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

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