CT50494

Painted routes Circular Route

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

In the wheat plains of Amberfield, Captain the measurer keeps careful count of the routes. Secure the caravan contract, every figure matters. 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 <= 3873; 0 <= m <= 3873.

Example 1:

Input: 2475 1274 1614 454 1362 1030 331 129 970 1379 156 1538 1611 1907 488 1433 2431 253 2129 2291 1955 935 535 1220 2446 1073 1824 1782 1836 2213 2186 1022 160 2457 817 1902 218 90 2453 191 2298 1895 231 999 1920 66 2348 1507 556 1263 1382 679 778 222 191 716 1918 1733 1714 1254 813 1803 1565 2204 957 1097 371 1602 1557 1125 920 509 1442 968 13 2133 648 2285 420 719 119 642 102 2127 1658 1247 1290 256 2474 1426 582 923 1747 2449 701 512 734 1601 444 977 1680 785 321 1957 1606 216 1074 1310 31 1646 54 1465 174 2425 229 1084 642 2164 1252 895 593 1584 1469 33 1734 2112 1575 646 2138 392 1989 1275 733 256 1202 1995 1149 274 502 2400 882 1099 1782 1518 444 1835 582 2342 744 2321 1857 479 2136 2118 277 1270 882 2088 1430 760 2157 1506 1155 1674 1086 1329 1729 1677 1540 697 924 1983 400 2022 973 1596…
Output: NO

Example 2:

Input: 1159 848 30 1019 927 417 909 535 883 1029 841 827 902 1056 402 893 184 948 350 617 48 665 1107 1100 130 225 194 480 754 1153 535 650 951 819 258 438 1014 1131 1149 220 1091 1151 380 246 933 248 489 129 75 401 145 911 255 29 17 993 6 100 793 705 572 567 2 748 597 606 390 1110 1003 118 335 1069 700 917 136 866 195 417 905 951 1011 938 16 319 797 1066 236 331 903 975 503 521 99 537 1016 1122 459 617 89 720 902 806 948 383 378 204 160 887 411 999 492 995 1018 822 517 401 291 768 681 370 18 605 297 724 263 765 430 318 251 539 99 752 339 9 894 886 772 931 1099 180 119 571 206 748 1128 843 24 766 381 927 36 168 603 326 786 88 340 20 394 690 90 1154 277 197 582 1030 534 22 694 612 681 613 1047 867 289 500 500 665 952 1024 893 600 404 599 128 251 479 292 289 142 637 156 640 981 118 473 1084 181 174…
Output: YES

Example 3:

Input: 1278 134 849 1061 1265 1249 303 71 488 976 723 885 1160 864 715 879 501 55 1017 924 425 253 1043 1262 547 1017 1164 166 1110 1241 1192 644 775 92 760 584 431 977 203 1275 1132 725 914 736 854 1254 12 917 347 674 15 264 528 771 447 166 968 45 11 1072 1036 486 218 885 569 1096 1178 679 832 977 1033 209 126 564 463 294 1116 100 1150 1114 1019 7 356 686 275 345 406 878 421 911 384 556 930 3 61 1167 1207 841 343 27 75 422 942 516 645 1028 504 1004 67 163 489 118 336 1013 1276 1222 1084 1059 1190 862 1059 427 829 1238 1256 705 331 520 337 703 621 1020 435 1261 603 245 1136 840 885 72 480 619 914 213 717 56 100 607 398 768 476 860 472 748 554 69 76 1073 1074 604 556 1091 482 320 363 100 546 1186 1192 712 613 322 353 390 99 829 644 911 1021 197 444 150 639 130 1000 1240 120 377 229 57 654 104 129 …
Output: NO

Constraints:

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

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