CT51281

Sage and the Circular Route

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The council of the cotton rows of Whitewick pays by the answer, and Sage intends to earn it. First: the full register of canals. 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 <= 2454; 0 <= m <= 2454.

Example 1:

Input: 1704 554 1651 419 428 785 654 399 858 738 811 656 719 1660 1495 747 1063 600 605 1250 1265 724 1428 403 592 720 399 990 1634 269 46 438 1002 241 46 157 976 1527 1649 1348 732 839 1362 571 135 409 352 91 86 1041 1529 199 190 259 254 805 430 345 552 513 1151 915 801 1164 1382 1323 135 932 884 1457 198 685 1102 1244 1532 1155 1421 754 1365 247 1287 1368 1245 986 1133 1505 391 1669 628 1670 809 1126 69 887 1037 572 1575 1046 1573 268 531 597 288 570 887 86 740 466 548 1523 15 423 653 46 1338 306 971 571 1488 1613 260 1423 1164 1087 1289 1186 232 1298 367 216 360 939 1317 1592 108 1484 1568 199 1241 548 616 14 1016 1362 1264 1042 1478 666 614 1363 1139 1315 621 634 1064 1386 286 1601 1695 1496 33 817 898 241 1150 741 271 743 1261 302 1056 867 752 1246 941 56 1005 1611 10 759 1636 1218 844 1370 …
Output: NO

Example 2:

Input: 1839 993 878 1055 18 350 1231 857 1671 917 1420 35 73 749 273 1836 472 1724 1254 1600 81 830 935 781 72 1289 1670 262 907 261 311 243 536 1077 36 1069 596 1506 337 941 1498 1708 1701 504 1503 1018 340 534 408 1234 543 475 1276 723 286 790 380 152 1100 1782 1632 1146 1335 324 1177 686 545 25 1762 1113 1258 352 1531 9 1358 645 992 1377 662 1037 682 1062 152 55 1525 1287 1008 1029 1750 1297 1708 1802 1362 651 1646 370 1568 375 1608 232 1326 662 116 945 408 1625 1538 1142 529 1603 518 885 335 1441 1729 1272 192 205 1008 597 1013 1793 1283 1169 615 605 1836 225 1055 661 619 856 57 1268 447 969 1239 1746 874 330 1260 432 397 1412 675 634 375 621 1718 1397 1375 1501 1378 313 931 670 1346 1144 12 311 933 196 155 14 110 1780 815 1811 1521 1161 764 1185 839 1406 1355 879 1043 1137 112 1130 1761 264 …
Output: NO

Example 3:

Input: 2185 871 1688 12 639 1463 1375 1140 38 539 1428 1052 2150 1289 1676 753 2073 7 1761 184 270 1946 1939 2159 822 1015 532 1821 2148 1113 940 1207 2163 51 1309 954 886 1965 1301 2117 2082 184 2156 906 738 321 343 1134 980 1578 1359 1004 475 1090 1887 713 1889 1541 364 302 1425 1871 1789 224 409 2000 1238 156 1074 1234 1184 1675 109 1653 1133 291 1615 802 119 1708 1721 60 1917 567 1726 1000 1431 1037 1756 1077 556 189 612 1298 1288 1704 1903 1729 1991 1571 87 1918 672 1591 653 142 1465 481 736 2004 929 915 119 1342 130 439 1783 511 530 1356 1732 1708 558 1289 1030 967 1485 338 1304 2124 860 1988 371 2017 1314 1418 1865 1695 865 921 1398 320 608 1093 545 1448 505 1236 1449 1480 1166 1207 1392 365 982 848 1580 544 2134 1124 1009 1362 1833 1434 543 1726 1226 552 785 2172 274 528 1642 2072 745 730…
Output: NO

Constraints:

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

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