CT53114

The Celestial roads of Kavi

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Deep in the coastal hub of Tidewater, Kavi studies rows of roads entries. One clean number will settle the guild's oldest argument. 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 <= 2675; 0 <= m <= 2675.

Example 1:

Input: 1931 1421 1745 1897 1499 1575 1410 10 1730 1683 1665 1035 84 1249 544 1524 1449 832 784 803 374 673 1402 1799 258 1672 298 1622 1421 1035 477 583 946 1362 1603 1164 1445 928 1706 662 682 1481 266 928 15 1549 1718 368 1134 841 1572 721 853 1162 394 1570 354 53 559 1510 1713 1159 955 444 1440 627 454 960 1020 1727 80 794 158 1508 1156 292 408 1183 295 613 1687 913 1477 1003 284 312 276 1125 190 1549 345 1338 1217 1901 1923 434 228 567 353 1236 707 837 855 1323 1629 90 1425 1620 1521 626 784 48 1373 76 442 1129 984 220 424 1399 1237 1702 826 803 944 1055 741 1194 1414 976 1529 1923 1060 420 664 1045 1243 1007 1284 1906 1712 1747 1874 685 920 860 1700 906 321 400 1624 250 1197 1075 669 1205 1665 1751 280 141 1476 1233 1491 343 423 1866 426 1685 948 830 1098 620 151 343 1665 287 1368 864 1462 1…
Output: NO

Example 2:

Input: 708 2028 36 671 630 156 226 690 39 339 587 85 320 111 483 537 192 244 268 566 494 417 337 213 653 399 494 306 281 233 420 662 414 226 197 87 578 588 369 610 648 443 236 110 288 41 27 239 150 420 19 245 607 301 470 301 586 290 355 333 43 228 100 253 169 673 453 302 310 392 510 156 196 434 621 89 630 386 362 427 564 385 191 249 696 318 361 244 333 437 475 307 337 599 478 290 649 264 604 276 519 49 437 658 131 701 235 20 227 315 258 438 353 23 67 415 187 311 587 106 529 622 233 82 145 313 636 119 308 375 424 299 449 537 704 79 82 329 84 613 461 625 215 402 552 660 394 119 317 166 451 115 207 370 392 406 286 582 261 66 176 211 308 363 458 385 380 388 263 222 411 21 600 145 356 600 330 201 555 45 290 73 669 86 55 111 394 215 141 219 165 698 405 393 543 566 16 193 188 401 286 308 289 563 506 573…
Output: YES

Example 3:

Input: 1966 317 315 1119 86 172 1808 632 154 948 878 966 1019 1247 726 1805 168 1102 1035 1291 969 1679 331 730 1279 1508 349 1261 1458 388 924 909 1475 24 208 1454 1597 1894 1069 1771 593 1022 1767 352 1415 1541 248 1628 1350 1092 1383 1796 506 1065 1875 57 1563 193 475 1788 485 258 782 1773 480 1811 845 826 873 704 783 1833 567 950 394 121 1660 1233 323 1098 518 257 587 1576 1954 545 1720 1533 74 1829 898 1610 677 576 853 617 202 1911 1175 1527 1071 1143 637 128 824 969 364 1664 1813 967 904 1044 606 1544 35 170 1099 601 1823 478 1531 182 211 766 534 687 1640 561 571 1349 1334 848 680 953 1274 1331 1074 324 1552 1199 1643 698 926 597 826 1683 1389 893 1563 942 915 1180 882 447 599 1526 724 32 1639 1068 1041 1887 1698 1755 873 1216 492 1144 1847 30 1807 1258 958 615 128 1254 722 296 899 1094 968…
Output: NO

Constraints:

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

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