CT54001

The bridges at Ashfall

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The harbor bell rings at the ember dunes of Ashfall; Devi weighs the day's bridges manifests and starts the calculations. 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 <= 3649; 0 <= m <= 3649.

Example 1:

Input: 492 3257 196 51 119 94 408 267 146 97 323 56 424 62 426 141 179 100 23 112 483 132 266 421 42 330 296 463 156 485 230 145 232 118 151 367 73 459 150 38 275 73 312 389 448 339 119 343 334 81 413 52 362 460 188 237 145 176 102 192 455 179 94 218 62 195 478 167 447 430 470 300 126 169 350 8 127 411 407 347 141 234 174 63 301 97 390 275 220 362 206 276 433 266 151 46 249 205 288 172 87 114 47 23 238 62 71 273 402 106 473 222 176 431 29 199 76 390 72 127 251 284 257 94 123 476 463 109 125 423 210 327 484 128 189 411 293 30 99 213 294 251 118 359 434 272 460 30 281 224 81 211 70 61 267 319 139 92 447 321 386 33 238 193 251 477 210 311 342 21 139 202 46 412 284 18 139 440 318 66 192 370 81 354 74 383 372 315 346 8 39 327 487 479 186 293 292 144 6 455 334 40 84 125 149 308 181 344 172 179 489 461 …
Output: YES

Example 2:

Input: 2906 372 2648 224 2121 289 221 366 1359 1133 431 2653 2772 716 1177 1555 183 1922 957 604 1820 562 1953 1079 1522 2826 2229 2139 2394 2011 284 1246 1725 1332 1111 2632 2362 943 242 633 2077 1909 321 772 308 598 833 2111 1025 1234 1089 2547 943 1548 1492 2009 1004 2249 943 87 2048 2161 522 1062 2218 2011 53 592 985 665 1554 1473 400 2897 802 2386 173 672 1393 168 2602 2086 1612 2307 2367 1003 1908 1188 93 2382 2283 2211 1972 1182 889 292 97 178 2756 1488 398 1130 2131 2866 1927 2833 845 855 2306 941 112 517 1314 1380 883 125 696 2406 2224 2388 884 2204 1983 1037 1158 424 1390 1005 2403 359 390 1966 1782 904 283 2625 1838 1758 1328 2504 764 25 1085 1043 2747 2192 2173 2836 2220 1738 2393 362 1210 1861 1373 1526 1692 1026 622 1677 2767 1732 446 688 2134 173 2730 1536 1943 733 1976 2168 811 15…
Output: NO

Example 3:

Input: 2174 3561 773 1624 69 109 2150 973 942 440 690 976 411 1013 259 1169 1883 544 716 1805 889 2065 829 1866 835 608 1038 1621 952 1918 1267 1723 2100 247 399 1329 334 218 165 481 493 831 1870 1253 81 1576 351 1377 1763 1463 1740 2137 1745 1055 1637 1850 1967 859 88 621 1783 2118 1285 1390 228 311 218 2020 277 219 719 387 1479 586 1559 768 1682 602 635 135 963 1235 1430 2128 1477 1458 324 594 896 829 2043 875 1009 257 901 20 816 505 1167 1522 1200 1128 1405 410 2026 1022 2089 1251 499 1805 784 2154 1185 18 654 880 481 474 648 1069 210 23 975 666 1827 272 2033 1124 190 2007 496 1138 1482 1041 1453 501 60 2105 481 1718 615 149 882 1389 405 1937 893 1080 40 930 1249 139 1934 1095 1420 1585 954 269 1467 545 797 148 1717 748 1118 2130 139 1518 6 1409 1420 699 117 1306 1975 294 1037 2139 722 1613 12…
Output: YES

Constraints:

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

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