CT48638

The Circular Route of Rainhaven

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

In the monsoon port of Rainhaven, Farhan the valuer keeps careful count of the routes. Inspect the delivered goods, every figure matters. 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 <= 2341; 0 <= m <= 2341.

Example 1:

Input: 2004 2322 207 1255 1432 1895 788 510 1711 157 1722 1532 1826 1061 239 1648 16 1406 1674 507 30 1658 892 1172 824 1599 401 1119 908 242 1247 191 1131 684 963 954 1344 665 1071 533 1758 900 1004 847 1169 277 158 1846 1772 1429 348 1290 1061 1907 1833 796 880 10 1581 1790 996 1477 145 814 450 504 1896 548 1346 1631 1806 930 971 1184 76 1296 1336 1325 1279 209 440 254 353 868 473 1000 747 815 1614 692 1015 1686 191 1802 1691 1222 413 622 537 530 1475 429 1171 292 1926 951 1879 1443 1164 1457 1461 1425 908 308 152 673 1122 240 1243 1878 1455 170 1807 1680 1420 1876 1552 209 338 969 1660 1835 794 711 333 1907 538 747 1965 463 1959 310 1151 918 1721 385 1351 1297 53 1920 306 1296 1214 1712 1905 765 340 910 1098 448 400 1110 1351 274 957 187 407 1884 859 1517 796 1783 677 856 170 762 1114 187 1062…
Output: YES

Example 2:

Input: 630 1497 577 31 498 348 571 321 624 563 517 133 198 296 621 193 537 5 193 276 621 276 525 111 405 99 111 185 408 406 58 336 399 624 79 93 343 95 140 121 35 414 97 476 293 509 490 350 13 184 334 217 254 270 191 270 114 483 625 353 383 450 158 74 159 85 253 538 324 333 54 377 237 411 218 300 233 418 168 223 570 88 181 357 606 547 453 472 346 472 137 558 485 413 492 527 579 248 44 338 180 7 252 50 237 39 225 553 458 254 597 529 310 318 442 415 453 518 204 617 273 87 243 26 74 431 40 202 348 316 446 425 294 69 169 565 306 21 21 522 627 203 236 212 257 486 225 216 196 234 498 136 493 231 491 184 130 138 497 227 513 79 88 117 231 99 566 405 145 67 361 516 305 3 464 612 267 388 171 132 43 626 129 145 167 460 180 513 457 604 630 378 16 186 410 26 1 465 324 77 585 101 430 572 481 84 107 581 209 515…
Output: YES

Example 3:

Input: 2071 2058 1340 1273 1794 1207 1079 1146 932 1013 1356 1621 273 1996 1798 1807 310 1058 1455 188 1483 239 206 1603 109 302 1319 1182 1480 1559 971 1928 528 796 1324 1230 2055 1284 1457 1087 484 256 1837 1053 409 860 709 448 612 756 1093 1042 1752 1990 1330 1308 1427 982 2049 15 29 1605 245 91 872 240 2 1916 553 44 29 2063 293 459 19 407 486 1571 1510 1636 682 1480 1306 1379 443 1676 1567 461 251 1862 1602 727 204 1416 531 1158 1082 480 1497 617 958 1333 1986 1531 1677 681 225 1053 1809 1066 1900 1510 1323 548 1835 1498 1208 519 314 1096 1932 1018 949 1018 1338 299 878 575 459 1956 794 1761 1222 1705 1822 348 446 656 1507 34 1278 813 1601 124 464 1239 1671 1357 1926 1480 1465 218 1824 221 1380 1250 999 1835 1087 1558 798 697 417 91 352 1921 1434 1506 750 1724 1180 1147 1414 2045 1745 1022 13…
Output: NO

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Circular Route of Rainhaven - MEDIUM Coding Problem | CodeTikki