CT56364

The Circular Route at Balmcrest

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Caravans arrive at the cedar groves of Balmcrest with crates of roads, and Jace the paymaster must account for every last one. 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 <= 2559; 0 <= m <= 2559.

Example 1:

Input: 1574 1028 937 169 853 247 195 1293 1513 429 1138 1390 161 234 1428 150 1466 1224 1429 1486 1107 556 295 172 677 1003 8 921 1478 960 570 1232 128 181 152 995 893 229 1478 37 977 1226 932 730 1132 577 1219 850 1560 542 584 346 176 98 1488 147 456 1091 1397 1286 1041 986 279 243 678 1559 823 123 510 407 913 310 599 831 1550 1199 711 62 1461 184 930 1016 1212 303 206 533 888 1061 697 1501 1401 134 195 584 1004 696 354 948 1398 1245 1289 676 874 1426 16 1092 195 497 955 1004 723 874 261 1530 982 304 789 254 816 116 1562 546 1025 606 1218 1443 194 690 730 404 114 1114 867 372 35 692 626 1155 627 1417 85 987 509 983 335 400 325 757 198 454 360 1275 776 458 799 95 167 689 986 1320 946 834 494 614 339 371 1483 604 1267 1160 1349 215 1122 1129 470 1030 324 1381 1242 958 608 855 280 246 1473 255 217 …
Output: NO

Example 2:

Input: 1820 1156 758 1739 706 913 1243 46 561 1234 759 834 1505 886 808 591 500 1533 1292 850 1228 915 851 1360 1358 1091 440 594 715 547 1126 997 1221 941 611 1076 809 1583 625 452 657 1018 182 222 1662 1747 506 601 574 1691 653 1294 686 207 174 436 1071 1212 832 1469 183 1739 1606 1018 824 280 64 1405 730 537 271 1185 794 865 1782 322 21 1287 497 1650 653 1775 944 1005 207 1482 557 1457 710 452 1493 929 101 1307 453 1675 1243 1173 486 228 2 559 1440 1014 790 245 1227 1101 729 1165 468 1026 1216 463 701 1108 106 502 1595 1485 1624 579 365 1484 707 1693 546 369 1683 821 1664 1634 280 863 881 63 1692 1090 405 323 26 1016 1720 185 1359 1507 1159 799 821 443 1780 1274 268 271 1053 202 654 960 1530 375 1704 421 1089 1248 1057 627 948 569 1591 454 276 1364 1135 666 1463 396 1560 133 628 544 850 1722 1…
Output: NO

Example 3:

Input: 218 1758 75 10 164 131 183 51 179 78 125 15 41 55 68 103 118 190 175 30 129 39 44 208 49 80 81 217 15 155 5 175 200 14 181 15 180 72 204 173 98 16 83 174 3 195 142 116 89 181 61 52 75 157 214 179 188 172 130 48 71 111 182 41 107 77 108 209 126 101 1 216 161 208 161 182 39 74 193 154 134 85 58 8 143 97 101 87 203 165 54 215 156 76 66 153 166 69 96 178 72 94 96 186 147 75 2 51 168 49 70 178 101 181 177 59 158 91 193 83 142 160 137 192 181 190 38 107 59 49 151 25 36 183 210 104 215 91 67 83 108 12 141 178 204 82 157 206 27 173 142 93 66 191 124 168 94 199 18 143 49 167 111 79 141 161 15 193 211 198 93 21 65 51 202 187 141 24 156 79 63 39 58 157 123 181 162 218 98 139 109 88 17 129 89 158 53 205 91 208 111 64 218 173 164 186 184 130 1 6 53 66 117 30 37 119 47 69 34 79 64 122 164 146 87 11 181 …
Output: YES

Constraints:

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

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