CT46940

The roads Circular Route Puzzle

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Morning light hits the old quarter of Brasshaven as Indu unrolls the day's manifest of roads. The tally will decide the next shipment. 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 <= 3098; 0 <= m <= 3098.

Example 1:

Input: 257 1309 246 18 92 168 77 226 175 173 98 143 241 63 84 83 48 90 225 132 14 167 97 171 2 59 21 55 173 160 130 96 126 231 229 217 51 182 89 41 176 110 170 203 241 186 15 201 189 230 199 38 107 73 34 85 24 256 157 116 235 73 201 88 159 146 199 212 239 203 144 129 17 235 171 153 187 122 88 197 34 112 12 30 97 61 92 196 140 257 118 182 188 164 91 229 58 139 52 63 203 243 55 226 121 81 196 55 18 21 193 144 8 58 109 16 12 230 201 141 240 231 13 170 215 184 31 118 241 118 37 77 222 110 80 179 81 145 176 243 140 27 78 110 204 207 23 134 96 177 67 22 24 183 3 256 174 94 60 106 8 151 154 197 38 173 224 77 113 160 216 149 21 244 9 203 94 104 244 59 124 113 207 103 192 237 256 249 31 209 21 216 245 131 171 11 19 10 157 113 28 50 73 152 143 77 81 129 209 231 254 152 41 71 182 93 237 6 145 205 122 230 1 …
Output: YES

Example 2:

Input: 1558 497 282 246 569 1301 261 363 647 1519 98 1048 712 354 986 1406 747 59 837 743 124 1021 1456 220 1066 150 1421 808 331 465 993 448 1453 261 122 808 258 1098 688 1215 326 1235 777 1334 55 406 1010 55 79 491 597 1084 520 539 642 626 896 1456 489 1234 205 760 1256 645 42 1507 804 1287 425 1534 839 1506 1400 1514 633 1121 1370 738 206 822 639 1027 1546 954 1330 1480 1290 1369 904 1135 817 607 1195 889 236 734 853 1154 1259 872 1332 667 241 408 232 334 121 1133 770 572 1075 1484 11 960 427 78 814 1056 1222 542 1192 977 942 1524 247 1085 46 769 1541 1238 1494 1140 385 724 326 320 1142 843 753 473 1125 521 192 1382 1135 1206 9 402 387 747 67 1149 378 1370 531 870 62 1376 279 1388 1203 62 370 539 684 857 827 101 478 719 1212 1465 1438 1082 1310 1490 59 1431 1373 598 45 1278 646 1206 832 769 85…
Output: YES

Example 3:

Input: 1145 91 1059 100 1053 391 110 608 607 740 322 208 1027 876 939 583 960 1015 919 154 786 763 796 28 963 905 824 151 159 242 918 722 685 136 939 1049 748 111 548 180 104 612 643 270 182 241 114 1049 119 727 522 119 578 783 131 276 150 1026 96 592 231 909 655 10 758 780 166 449 404 210 240 93 400 274 182 603 251 993 309 162 643 423 1056 882 720 153 1021 542 87 5 936 1014 171 951 1047 359 628 352 735 210 595 970 791 419 757 726 785 517 215 37 985 282 150 775 206 572 1092 421 85 945 559 552 97 873 66 924 697 122 970 136 8 1050 225 1026 332 993 758 349 650 264 1139 971 275 65 106 529 525 1106 1015 1017 430 190 68 455 276 31 729 60 1061 641 568 781 563 613 678 439 894 112 767 188 410 273 339 390 940 177 54 702 520 298 261 563 689 225
Output: NO

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The roads Circular Route Puzzle - MEDIUM Coding Problem | CodeTikki