CT39039

The Tangledeep Circular Route

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Caravans arrive at the kelp forests of Tangledeep with crates of corridors, and Lakshya the clerk 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 <= 2037; 0 <= m <= 2037.

Example 1:

Input: 575 1332 324 96 444 261 332 119 488 116 111 264 199 425 503 376 534 284 333 111 532 573 35 205 253 461 18 78 375 266 350 95 192 94 491 569 366 550 467 479 257 454 450 298 214 439 56 489 209 408 231 477 229 245 546 316 41 159 273 233 283 230 562 30 324 537 171 297 28 145 42 402 378 118 342 481 293 490 186 20 472 297 105 459 21 424 405 124 485 440 73 332 150 463 51 311 503 78 250 293 544 565 526 278 313 59 33 514 19 65 432 343 336 426 202 61 559 470 534 427 512 114 463 424 263 369 2 467 110 268 457 99 20 27 255 262 44 124 547 111 174 274 546 105 81 267 395 483 448 297 186 540 281 212 567 14 456 248 326 217 444 147 184 558 225 445 537 478 290 70 499 109 502 417 235 126 370 269 436 277 382 292 23 196 87 511 208 277 144 250 249 358 501 275 433 459 409 61 477 451 349 443 79 451 297 335 451 79 46…
Output: YES

Example 2:

Input: 1989 1229 1892 1272 1333 1525 473 420 488 623 1533 507 298 1193 1448 1371 677 638 523 676 244 1605 1610 1564 1270 624 511 232 938 632 1079 516 221 1619 268 489 1898 94 287 1122 1009 510 1455 383 923 165 1928 1759 210 1274 1663 606 989 948 1490 1614 1735 1001 1224 1008 1721 1403 544 1882 235 1884 975 1802 1836 1601 1744 738 271 1475 1602 333 1976 1741 1626 1057 1235 492 1837 1527 1222 1610 1235 549 576 805 86 1105 1635 985 821 194 1212 577 1151 77 342 613 1080 1502 1962 1805 1666 1808 1024 1116 816 1505 1048 1950 1523 593 1304 1909 787 807 1037 1673 900 790 629 774 770 1882 768 1481 883 1984 1427 1601 708 160 878 1505 270 1061 1514 842 62 1627 625 1015 1565 686 1751 1852 309 1202 995 1672 1156 1789 1135 605 408 1396 1097 1608 1307 1324 318 1706 1490 520 1164 1841 712 946 229 899 1180 1311 8…
Output: NO

Example 3:

Input: 276 305 41 274 63 223 272 108 263 88 259 89 130 200 33 247 46 31 116 6 73 213 12 7 78 5 195 164 61 100 243 103 90 124 144 11 231 249 91 45 87 192 191 231 73 31 210 181 178 112 120 39 188 235 249 80 99 60 67 44 11 153 232 54 179 96 221 199 71 134 210 133 112 83 261 274 135 224 251 98 198 65 211 150 109 186 243 102 269 265 29 265 112 20 119 70 212 17 169 208 244 156 106 233 37 234 241 62 17 241 201 188 72 18 219 27 216 125 130 2 245 147 168 130 127 263 44 136 116 130 144 19 271 119 269 72 121 133 269 221 257 265 262 227 216 99 159 44 114 181 121 66 171 6 45 22 196 224 59 130 238 263 53 77 145 229 118 263 19 57 196 239 129 198 181 23 6 128 126 22 48 226 79 142 58 52 117 166 171 118 161 112 215 205 133 241 157 40 81 109 98 30 178 9 252 162 224 43 35 66 241 159 167 85 74 153 11 174 202 107 231 …
Output: YES

Constraints:

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

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