CT43492

Sara's routes Circular Route

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Sara inherited the tannery at the lantern district of Glowfen along with its curious bookkeeping system for routes. Time to make sense of it. 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 <= 2666; 0 <= m <= 2666.

Example 1:

Input: 630 2153 327 57 307 534 177 3 142 188 101 254 304 599 282 351 227 169 185 233 524 622 253 129 521 433 330 293 251 401 302 233 327 32 599 390 73 377 96 221 9 422 284 123 273 260 541 605 366 620 36 224 251 291 335 17 181 79 316 92 505 26 425 331 611 492 180 436 431 114 70 463 107 245 306 599 315 2 220 239 369 52 88 608 411 418 588 431 362 216 600 328 430 296 370 318 521 540 227 23 378 162 594 347 257 426 96 589 158 115 581 128 531 443 236 275 36 435 514 213 47 354 293 510 424 329 136 612 527 162 98 359 124 511 455 42 578 405 217 569 267 164 518 508 608 391 24 548 469 303 538 450 525 157 489 233 483 479 604 20 29 102 570 630 29 469 216 369 77 335 460 324 519 559 427 565 323 441 225 352 574 575 294 518 345 234 564 601 206 209 141 280 422 145 353 65 587 426 363 183 572 493 435 137 571 457 175 2…
Output: YES

Example 2:

Input: 2316 742 490 58 1615 863 1346 495 509 1091 2270 706 1075 47 1692 1612 1427 47 1957 775 2090 1150 789 2200 1974 790 1074 862 2097 2044 2100 308 2247 423 701 991 531 1223 702 2256 1076 187 1905 1137 1320 1621 809 574 315 2262 809 330 1967 1448 868 1017 296 2165 576 1236 1369 1932 235 1983 1608 686 1212 142 1970 2224 544 1783 981 451 654 1087 281 2176 1292 1002 2236 692 245 764 1212 940 1064 652 1484 1410 1019 1145 868 1830 713 1687 2009 445 1653 129 440 827 943 866 12 2299 2092 842 397 1002 2231 1221 89 2291 536 2056 1059 2113 1979 308 1721 859 1971 1306 1645 558 290 1738 449 220 2013 1466 614 454 1128 854 1786 990 1903 1373 1966 1663 1006 660 1967 1895 246 1437 200 254 626 1172 1333 616 1322 2094 1413 60 1704 1359 386 2287 184 53 1957 1539 351 580 309 877 2238 83 1713 1119 898 643 76 1786 9…
Output: NO

Example 3:

Input: 281 286 32 210 170 69 145 173 143 255 73 180 70 209 15 65 277 88 202 272 198 90 40 44 210 5 125 137 96 114 40 246 236 77 13 112 266 18 15 149 46 210 167 205 234 50 128 100 214 130 175 129 149 145 169 172 102 176 159 95 237 63 264 49 81 86 101 77 38 62 95 85 36 259 35 96 280 194 103 219 5 20 20 221 161 143 59 70 29 149 265 117 154 28 210 216 139 218 175 248 176 63 26 120 172 118 263 272 56 243 208 68 57 52 93 244 118 148 129 3 24 163 67 245 181 65 181 200 202 105 170 100 3 142 193 195 41 81 78 33 56 247 66 31 57 74 210 50 17 160 146 250 46 101 187 50 262 122 113 142 143 15 131 191 193 112 189 143 177 247 59 23 205 9 200 78 196 205 23 59 279 52 262 145 46 192 137 158 40 259 175 112 249 206 245 168 200 267 265 56 99 89 154 253 68 250 58 281 188 279 116 102 172 253 260 87 100 205 274 229 266 3…
Output: YES

Constraints:

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

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