CT56789

Coral bridges Circular Route

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Vigo runs the mill at the tulip beds of Bloomhaven. Today the books show a list of bridges, and the numbers must be worked out before sundown. 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 <= 3674; 0 <= m <= 3674.

Example 1:

Input: 3164 172 2909 718 1318 2305 2405 1589 1233 1672 560 2916 1557 1483 77 1706 259 2868 395 697 618 353 182 2107 2646 2623 2713 552 1391 607 160 1807 1757 2778 428 762 1139 1189 2583 1861 1661 553 2061 1215 19 868 313 2948 1156 530 2273 2618 3078 1625 2832 2778 549 154 1417 659 2636 1029 1524 1915 2179 217 2778 845 2899 365 2556 547 2536 2692 3143 570 2767 1407 809 2240 1406 3143 157 1061 150 134 546 936 311 881 1155 1182 159 2785 2525 566 601 3005 1312 2141 1088 2176 2910 1097 2603 95 1223 2200 2796 1403 1190 2743 2022 1099 2494 523 359 1404 1207 185 2166 968 2807 315 828 3043 875 2061 1340 1396 993 1526 1983 1603 2023 162 307 466 1326 1116 986 1198 2243 383 2808 2818 2240 2743 2955 923 3094 3005 1552 2905 2028 1041 1490 1763 2735 2813 2233 816 2963 270 1420 2534 943 3045 1838 2463 1367 2512 …
Output: NO

Example 2:

Input: 1466 1111 474 1127 1103 137 1294 265 925 473 1195 1292 678 679 308 1263 1318 855 1093 656 1187 1136 1307 585 534 1228 565 137 1300 969 573 1347 97 1131 498 40 173 752 1169 898 1464 773 892 1345 345 1257 944 268 290 10 395 1261 1449 1077 262 1435 597 671 968 1434 330 348 534 978 380 129 924 1137 778 1082 140 705 261 788 207 1390 358 387 741 748 264 1053 278 110 597 1059 651 41 1121 651 469 250 898 1146 1244 818 105 366 1143 740 924 285 181 834 783 883 1104 285 1345 26 1271 938 1335 605 127 658 1087 105 338 1365 422 950 249 207 972 99 1201 676 992 696 468 156 1211 1026 1363 122 259 698 1250 1265 426 1288 1443 1268 1370 403 37 285 19 992 153 561 942 1044 953 1218 225 703 105 971 1039 254 546 1121 61 57 21 395 497 1329 940 1256 48 779 924 509 828 1039 580 718 794 408 513 551 482 443 1044 333 8…
Output: NO

Example 3:

Input: 1757 51 900 1532 1541 1322 684 1124 1611 1205 815 1167 949 672 278 939 1582 686 1018 1651 188 986 515 340 810 882 38 329 454 36 1441 1306 1306 1206 710 238 291 1748 32 746 1104 1177 452 544 497 498 44 462 34 13 1684 723 465 538 1030 868 727 1264 1748 256 397 98 548 539 567 1618 668 1461 1328 72 610 1672 435 312 1173 1400 232 1302 155 960 615 1661 1614 1247 912 177 1482 760 458 854 1232 928 1287 1565 1258 77 1402 448 495 1103 1613 759 85 348
Output: NO

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Coral bridges Circular Route - MEDIUM Coding Problem | CodeTikki