CT56844

The roads at Bloomglass

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Lothar runs the boathouse at the orchid house of Bloomglass. Today the books show a list of roads, and the numbers must be worked out before sundown. 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 <= 2308; 0 <= m <= 2308.

Example 1:

Input: 1905 1161 1712 814 1571 636 824 86 313 1620 305 536 1577 1400 1666 1042 1658 1899 707 1514 1738 1550 163 200 736 1240 888 1190 752 1606 761 182 1025 18 1576 1298 388 1605 600 1235 1136 333 1257 1260 1135 132 740 342 1119 656 816 515 1233 878 1598 779 310 739 1366 1511 1341 1358 1083 1208 824 864 21 1121 1730 356 351 1349 1124 463 604 1778 1112 1557 851 1211 1292 394 1304 586 613 424 1799 1236 1387 687 152 937 516 66 389 170 674 446 820 699 1767 582 1649 1672 346 1849 547 747 386 905 390 612 681 1652 1499 783 925 8 1106 650 99 511 1829 1239 1200 1085 844 1694 946 1003 252 1678 829 564 500 1635 1232 676 1796 773 82 213 611 290 1574 632 1159 517 1890 181 44 1734 192 1325 627 1742 131 1808 1122 677 178 950 139 361 1791 1316 410 1854 1413 459 1724 1811 908 553 1333 753 1183 1688 1673 925 1757 1…
Output: NO

Example 2:

Input: 2237 155 318 307 989 1074 93 2010 494 1275 1527 940 959 1077 26 1392 1031 1936 1638 556 822 45 2010 1528 1151 884 1344 815 1938 1948 494 1733 1127 1070 649 622 997 2225 2116 489 1402 2091 60 2172 1463 137 2032 2218 608 2136 937 1619 453 1488 933 1162 539 1378 1501 1559 969 156 466 1376 122 510 266 1007 407 203 848 184 78 2073 1977 1955 612 244 1493 1005 341 1092 999 1064 823 1422 414 1688 48 925 1798 1935 785 2013 773 1032 2231 834 731 2220 936 47 2069 1619 261 1126 1204 1242 1462 1259 1586 861 687 1877 1195 864 396 1470 15 1724 1237 1733 505 1083 339 575 1171 896 244 926 240 1048 36 1662 1800 1131 64 1023 1727 1255 2199 1362 991 1434 1389 1798 296 80 2052 384 1183 920 391 1147 626 1324 1552 1097 971 1083 810 1371 1672 151 2208 1680 1404 1602 896 1619 1434 956 1990 1306 635 2100 297 1895 1…
Output: NO

Example 3:

Input: 1705 1114 1624 1547 1327 691 1012 1584 923 940 205 1366 1671 402 245 851 1508 438 1079 373 751 969 765 926 1655 16 703 1042 1689 1037 911 1505 1428 1095 275 1465 238 154 817 1360 1620 741 1573 1205 459 1092 841 21 70 158 143 788 1439 1631 119 1598 575 1193 249 1640 4 1171 1365 202 1421 1407 797 105 413 484 188 1320 1504 179 318 1539 366 1406 453 411 1333 363 1082 426 1541 405 1651 286 628 471 1697 349 1318 487 103 301 1426 817 702 1656 1341 1428 1584 367 1646 1268 245 1136 1072 297 1652 1091 369 1329 1034 1621 532 758 1474 426 75 582 1607 1565 837 845 1161 1554 1081 660 1486 1599 854 1497 1138 1407 396 465 355 1141 635 539 258 216 700 534 1699 1659 935 85 346 7 644 186 211 378 607 553 559 1577 15 541 1417 258 1235 1006 57 1381 92 677 147 1300 454 1585 1193 1543 1208 6 1477 971 332 245 994 …
Output: NO

Constraints:

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

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