CT42573

Rhys's roads Circular Route

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Legend says the vault under the shale slopes of Greystone opens only for a perfect tally of roads. Rhys means to find out. 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 <= 2913; 0 <= m <= 2913.

Example 1:

Input: 2170 1127 2012 1858 127 23 45 2096 1476 1260 305 718 604 1407 1702 1519 1581 1371 1749 223 1953 173 895 577 430 1672 1839 1255 67 507 794 714 194 348 1957 1927 1454 2099 1745 138 94 808 258 2098 880 766 254 605 1960 565 2126 1321 1013 1259 226 123 495 1503 957 2046 68 2041 1892 1741 1996 1379 2051 1737 627 1693 1237 1958 1140 2063 1873 1634 1608 1943 2123 484 1311 80 1997 30 1836 2087 1384 2019 924 1902 266 195 2124 1119 1889 1404 1490 1617 600 1981 668 1843 227 1955 84 67 1737 1851 812 422 1540 1776 477 54 2125 683 282 762 118 255 1628 1678 962 448 816 351 216 957 2094 1328 2061 17 1094 2039 898 1202 1363 1415 280 1915 1936 856 1057 1911 1996 1911 265 71 958 1637 2046 798 33 251 388 697 2160 273 628 1672 1886 671 2052 118 957 122 1118 1037 585 2038 491 310 129 416 1895 2118 1369 700 729 2…
Output: NO

Example 2:

Input: 1753 2783 1614 75 999 416 1135 1677 1016 1108 538 136 576 1337 1098 615 1575 140 173 58 941 404 650 643 363 385 1103 1333 872 1110 18 1235 873 894 323 828 837 1109 1751 1347 504 1525 733 180 739 1283 775 194 505 1230 931 800 375 1342 720 768 1658 1505 1049 1586 1143 1549 1034 1493 820 1402 27 651 1107 1300 117 528 388 1717 1073 1124 800 1558 1358 1083 531 907 1222 1145 639 1514 93 1543 219 265 266 127 682 540 1112 449 490 23 1210 155 1240 1315 1707 409 899 1176 763 618 1420 464 1714 1217 1036 902 1281 1742 683 1371 1318 868 23 162 933 610 1579 964 137 1238 1168 939 641 614 452 642 309 124 622 28 1141 576 1162 645 822 1376 585 654 781 1675 401 556 708 1653 1111 70 1570 162 121 1583 475 531 179 258 973 1735 308 848 685 591 1616 817 1406 1309 804 827 731 256 1318 1522 695 979 1665 55 606 259 …
Output: YES

Example 3:

Input: 615 800 517 371 529 212 451 247 210 79 445 284 443 522 541 13 71 15 196 144 18 356 248 326 121 25 254 455 388 117 216 607 41 152 110 527 427 57 579 376 189 583 339 85 408 230 242 465 457 253 573 353 86 288 587 83 193 309 48 470 257 411 55 605 132 240 171 279 53 196 614 340 170 60 136 228 544 308 156 93 234 192 329 87 11 203 241 82 519 330 135 232 397 184 437 365 102 177 359 231 341 113 368 13 515 188 601 62 595 128 78 65 18 588 293 58 155 534 301 592 76 188 126 293 63 154 587 432 575 83 185 357 151 340 7 149 525 575 537 395 4 212 575 152 141 247 162 7 461 518 66 5 603 63 360 418 210 184 570 536 197 348 495 21 43 203 143 547 195 123 69 514 185 133 573 451 415 399 184 294 263 256 127 40 71 57 522 583 530 303 247 67 79 24 402 281 165 124 478 594 204 338 447 372 614 484 367 610 128 375 3 249 5…
Output: YES

Constraints:

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

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