CT41563

Tarun Counts the corridors

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The council of the coastal hub of Tidewater pays by the answer, and Tarun intends to earn it. First: the full register of corridors. 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 <= 2258; 0 <= m <= 2258.

Example 1:

Input: 1604 20 172 1125 891 1535 2 136 546 928 1445 1267 1135 106 969 157 844 872 48 72 793 81 627 38 823 1345 1276 992 335 12 309 1533 1514 1408 851 850 16 85 1389 1456 1086 685
Output: NO

Example 2:

Input: 1535 1717 1172 1461 423 1030 1405 300 891 309 346 953 229 1498 1062 1188 873 436 24 423 1085 586 1434 1294 1373 1113 958 1030 642 389 363 473 812 289 464 310 437 412 364 337 630 100 1479 847 1209 564 792 92 741 1134 216 572 574 372 200 1063 1335 284 1465 925 1279 655 960 821 1526 778 1233 242 629 1058 154 353 1136 1463 1287 306 1527 1419 984 1263 314 1031 160 799 1004 274 1117 1020 145 1464 680 474 798 1396 470 1514 928 447 836 1101 347 202 379 193 610 950 3 90 1379 937 488 306 478 316 836 495 1288 266 1500 782 105 903 1191 948 951 524 219 843 582 974 1036 1264 1240 242 1020 1357 1493 133 1142 773 394 1195 700 550 1047 1214 1203 548 1399 277 1336 568 152 1071 493 107 1263 1003 958 1232 735 631 1007 626 1000 467 1313 1152 611 314 423 1046 945 570 999 1214 389 397 350 767 581 231 1307 1059 5…
Output: YES

Example 3:

Input: 2072 379 2037 915 1987 826 498 1540 1851 439 984 680 293 177 133 1578 1703 1167 1728 983 287 2035 767 358 1880 1610 936 372 394 1684 348 364 2057 11 825 468 1949 778 737 2048 2039 717 1403 1416 234 438 368 535 772 1515 1009 1705 83 1719 701 816 511 112 75 1669 1785 1756 754 1095 932 682 811 520 243 1458 160 1441 1679 507 1840 1482 1848 1377 1818 1107 367 1875 916 1232 1856 1239 960 4 1326 664 2010 1140 718 1436 1969 1985 1660 1336 868 1892 79 1369 263 1717 2018 1946 705 2042 650 1236 840 703 383 365 1364 576 343 579 1058 461 2043 706 1808 19 380 1138 1918 1238 2022 1020 757 86 516 987 280 811 102 1611 88 1308 100 320 1420 242 1192 534 1274 161 1398 199 1877 584 1156 412 689 119 1914 813 1167 1817 100 1749 1267 844 1328 1561 1666 825 1991 932 127 1146 553 60 1861 667 1353 997 1249 315 626 1…
Output: NO

Constraints:

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

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