CT52679

Farhan's routes Circular Route

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Legend says the vault under the kelp forests of Tangledeep opens only for a perfect tally of routes. Farhan means to find out. 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 <= 3322; 0 <= m <= 3322.

Example 1:

Input: 2196 1539 1539 538 1421 204 1528 612 203 1763 502 211 1189 285 41 1007 505 1721 374 897 1849 209 1030 1098 1638 1783 790 1287 1868 1134 2175 1653 329 217 1396 421 659 2067 1271 410 1155 591 1379 1597 1136 1469 1886 354 829 528 680 1582 1271 327 1598 591 1438 260 929 1544 1785 1288 1907 1167 579 1118 2170 1176 669 667 2155 1499 1393 682 1194 1625 7 1428 1852 1865 1920 1146 165 2110 881 1545 346 1508 1981 831 1006 384 938 1928 1490 161 675 191 425 871 1178 20 1362 1038 1665 1662 350 1172 1689 1373 305 2167 1949 246 1653 2056 763 1304 922 2025 358 1224 1383 1377 1962 1953 1795 1047 1600 722 1490 2181 646 212 1523 1387 443 1759 428 994 73 631 1502 890 1918 781 733 1669 1568 1728 1194 1728 1945 2031 280 897 1948 1306 754 118 1688 1058 1621 1815 909 588 672 982 1565 847 1154 716 1385 1495 702 17…
Output: YES

Example 2:

Input: 1290 2636 385 528 1020 860 1112 277 607 664 106 817 473 774 780 991 1162 53 614 509 23 628 333 1254 1194 1114 998 612 75 881 688 1195 10 1128 1278 348 1120 881 1136 417 58 270 1260 157 554 538 756 62 598 627 1214 120 951 186 789 472 1177 982 317 1094 1088 667 222 1067 99 538 1086 1138 493 576 796 1256 1196 150 642 654 448 908 15 965 438 849 133 410 95 500 545 163 442 290 1283 79 780 617 344 515 1042 88 1247 869 264 1257 287 406 979 582 379 523 461 797 106 398 1227 1141 975 1256 720 195 570 258 1180 507 509 1094 290 1118 938 705 339 740 654 800 445 834 720 1170 839 849 894 617 563 320 317 975 683 301 1167 648 1246 867 393 899 898 1027 1174 1289 45 584 429 770 1152 674 720 1287 335 165 716 788 1146 902 755 237 278 1266 774 14 1244 266 1242 95 1021 1226 917 879 575 207 767 971 284 256 390 123…
Output: YES

Example 3:

Input: 2130 2871 1714 549 1050 1078 789 1085 738 220 1160 516 1167 373 1251 115 448 207 597 2107 232 733 1284 1563 998 297 1161 264 1364 1426 588 1213 1695 312 1362 680 1854 595 2020 402 1372 1572 1177 1248 506 1219 2003 1573 2064 715 513 190 1849 1934 2128 1648 513 163 2006 1874 1734 215 1186 423 357 367 1839 1333 283 1117 1898 1621 1919 769 6 259 228 805 1226 1637 1395 1869 402 118 708 1240 601 865 1839 599 311 1465 1839 1044 1532 78 164 1919 636 2014 1290 1217 1560 1759 1191 1133 1766 1795 141 182 1399 1195 699 1896 209 1101 1973 932 780 851 2057 925 1085 1370 1629 619 567 1160 1185 673 1470 653 1164 2001 1904 387 38 519 1704 796 512 157 1220 1514 1197 1430 198 855 1289 336 1096 1975 1552 2018 1153 981 1433 519 40 1020 443 1822 1194 1887 1076 379 1103 1934 506 1784 488 897 1477 1756 2002 592 7…
Output: YES

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Farhan's routes Circular Route - MEDIUM Coding Problem | CodeTikki