CT39145

The Mossy roads of Lila

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Caravans arrive at the salt flats of Palemere with crates of roads, and Lila the clerk 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 <= 3123; 0 <= m <= 3123.

Example 1:

Input: 780 1396 458 111 264 219 412 6 120 763 149 688 701 615 21 446 734 328 108 174 140 404 309 615 458 406 210 357 759 578 726 601 331 352 501 515 393 323 300 512 116 223 357 303 12 516 64 72 379 668 40 370 40 376 658 12 767 509 742 2 134 203 16 218 767 339 329 123 538 371 373 711 565 658 606 339 579 176 327 334 753 500 382 7 125 529 236 734 473 461 561 690 343 515 743 107 412 243 552 616 734 374 422 438 202 545 649 504 13 648 266 710 549 129 384 156 425 652 715 157 679 214 148 71 579 241 204 358 695 742 624 545 194 469 473 14 433 99 371 174 468 259 52 537 346 615 455 393 283 74 447 17 588 761 548 425 483 314 556 710 463 202 370 354 757 657 484 89 542 486 719 615 261 493 522 537 536 335 574 411 48 228 148 398 384 424 748 180 582 365 136 60 397 37 7 465 91 394 2 452 238 359 596 230 148 507 518 5…
Output: YES

Example 2:

Input: 2221 1424 1281 1095 357 241 651 445 1083 987 686 1979 907 1672 478 2135 1263 622 1553 1125 1655 1044 2218 868 1401 1247 254 2095 902 427 1533 2016 1763 1003 35 936 1109 1859 1220 1689 136 2020 111 1681 236 1630 810 652 1178 772 4 352 1672 1669 1758 2111 746 515 310 2217 2061 1482 30 1981 1853 1102 188 1315 1429 2081 150 30 1157 1857 165 2009 2087 1903 2084 292 1177 2139 336 298 1530 512 1891 2164 1521 1502 148 1775 727 694 615 1301 1440 1826 1776 236 2004 1332 949 903 1296 1771 1493 87 2175 813 671 1378 973 381 1139 2170 519 1027 623 1179 1814 1255 1998 1956 1520 1495 2134 1701 1297 1497 830 285 1399 1735 675 1001 1226 1572 1681 36 909 1055 1268 1476 906 547 1767 1249 1694 1159 1994 1061 1707 1508 23 1034 507 918 926 1882 1395 1289 1716 190 1133 169 2148 1920 508 884 1989 2105 952 1835 685…
Output: NO

Example 3:

Input: 2256 1985 994 725 1072 2074 2245 1844 263 1028 1850 221 323 1215 1311 95 379 2136 1159 60 471 57 1013 1377 790 774 758 154 1094 1240 559 524 258 1444 966 825 744 269 1942 2231 969 1850 575 1028 492 1820 1753 2084 592 1613 1583 1113 360 1634 249 1067 436 57 1023 555 1207 1265 564 1316 1404 1952 1239 1158 535 205 1569 1795 557 39 1770 1591 820 1292 1582 1726 690 433 1156 956 581 340 691 1139 959 253 457 865 629 1602 611 1409 2055 589 811 310 1242 804 2171 538 1676 1195 1542 1363 1141 196 314 865 1398 829 1945 1832 867 848 731 392 2164 327 2155 1489 2177 117 1131 2120 1594 568 1819 499 294 1617 904 1684 1007 1414 369 1469 996 2011 1810 2169 2151 1663 836 289 1099 170 1766 1762 2029 1241 399 1880 143 548 1203 1325 906 1817 79 580 1201 701 1669 1365 839 158 1980 2148 1916 963 1621 377 1189 1029…
Output: NO

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Mossy roads of Lila - MEDIUM Coding Problem | CodeTikki