CT50984

Parth's Circular Route Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The harbor bell rings at the sulphur springs of Brimstone; Parth weighs the day's routes manifests and starts the calculations. 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 <= 2469; 0 <= m <= 2469.

Example 1:

Input: 259 1791 95 128 163 113 190 49 72 233 118 224 252 226 7 240 128 42 135 92 195 1 75 18 239 138 31 135 64 238 6 242 71 15 181 222 101 193 187 116 28 135 226 237 205 231 160 13 6 188 107 201 43 162 178 120 187 79 160 21 242 230 103 5 58 209 118 15 105 130 218 30 47 86 76 84 161 248 132 143 34 73 112 33 19 68 160 92 159 174 227 240 58 135 62 13 6 119 223 131 57 132 105 77 190 215 163 106 81 209 239 64 55 216 209 169 258 115 211 52 175 137 23 119 76 121 209 95 135 253 23 86 197 77 158 111 97 165 220 45 73 143 15 29 57 257 175 21 149 209 57 239 44 56 61 95 221 24 163 89 84 116 4 232 240 200 54 150 47 141 46 17 233 16 211 123 9 17 118 103 229 214 47 123 124 90 67 8 127 199 79 239 202 244 240 122 231 179 180 222 250 156 234 173 227 245 107 249 2 217 209 84 64 161 150 108 145 167 41 42 175 145 59 5…
Output: YES

Example 2:

Input: 2241 762 2017 1857 759 964 2147 2123 1486 344 450 1051 1297 1229 666 568 684 2013 2221 1804 705 16 1872 1348 1073 1108 356 123 2160 269 1060 1596 387 2020 571 1713 212 551 1139 931 193 369 1781 809 1553 1232 1582 821 1263 279 1743 757 1036 2130 815 513 1629 451 408 1038 88 692 1258 458 2194 792 254 324 1371 377 1504 38 800 2000 997 218 1789 1091 1066 544 1404 1293 588 218 154 102 448 597 900 81 1501 1969 1916 701 1683 1429 1897 425 1389 314 1975 1681 225 2051 461 564 683 1008 1160 1800 965 970 2158 1918 995 1459 1664 2065 61 2071 1837 2036 663 1061 1495 120 786 824 2226 191 1535 1348 116 1222 690 127 1017 185 1373 75 1802 1726 880 756 59 1753 217 1684 100 1891 1490 1505 451 1872 1918 2163 38 638 1850 1813 1457 788 1478 608 815 1427 949 1353 630 23 417 1625 599 1152 829 1578 621 1019 88 159…
Output: NO

Example 3:

Input: 531 2217 186 304 262 38 183 511 254 210 350 276 480 269 376 169 240 471 23 429 60 388 30 159 161 17 382 113 366 180 130 472 458 427 110 399 434 308 89 456 21 495 488 291 93 274 312 120 246 52 76 522 365 377 383 524 349 53 480 42 3 370 258 398 372 287 436 236 299 99 142 436 402 197 306 453 491 448 152 255 50 189 386 25 25 351 167 505 69 63 298 223 196 409 323 96 316 335 319 150 240 408 480 272 427 491 407 272 268 391 45 386 84 296 284 475 254 235 81 431 77 312 75 96 403 357 157 151 342 322 485 264 285 93 109 137 472 127 386 510 93 247 429 315 95 504 276 22 120 11 34 337 247 298 518 113 491 405 529 435 498 157 174 193 308 401 235 258 517 478 361 66 370 267 416 31 245 236 297 342 16 338 362 131 358 189 82 365 425 224 395 377 191 381 36 280 261 136 193 465 193 246 123 368 260 222 296 134 505 2…
Output: YES

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.