CT41552

Saffron bridges Circular Route

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The customs officer Gino has been asked to track down a clerical error. On the desk lies a long table of bridges readings. 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 <= 3380; 0 <= m <= 3380.

Example 1:

Input: 2617 620 1934 291 2113 271 1219 2453 2568 2505 1674 1350 2307 1406 256 1533 1956 665 1431 2600 1719 371 2587 2051 1709 2606 1806 343 2523 2531 427 2251 192 2347 908 1460 2454 1348 1318 1882 2419 1277 1098 13 2018 2177 1153 1042 2107 2242 971 1457 1940 169 850 1157 1590 2592 1784 1341 310 457 232 2107 2346 1398 1226 1922 509 1468 1559 1468 2569 1893 1861 738 1794 1977 109 1267 1250 1123 2286 1393 1910 2540 1550 607 2583 506 1099 467 2117 415 1265 363 826 1333 1790 221 735 1507 1341 2302 1159 128 214 2430 2266 2354 435 678 323 118 6 96 1794 1848 499 550 123 948 1538 2163 1547 1568 1488 1928 952 94 734 712 1971 415 244 1135 142 30 606 133 1712 1685 2563 1758 1206 817 1530 826 2382 658 2580 402 1874 1631 594 1594 2166 278 1085 1477 1927 600 635 814 453 1654 1918 1904 332 1995 2540 1260 904 910…
Output: YES

Example 2:

Input: 42 280 19 14 30 38 39 25 34 14 22 18 23 15 6 40 5 40 7 29 16 2 24 16 31 6 39 4 41 39 22 36 27 19 12 6 23 24 29 34 23 14 17 11 33 23 28 20 6 26 20 25 14 18 17 34 7 35 42 31 4 41 40 36 25 36 33 15 7 13 5 36 11 6 31 16 21 41 22 3 19 24 35 24 9 42 30 35 10 8 18 27 32 8 13 18 22 16 1 42 37 17 4 1 15 30 13 31 9 18 20 41 25 22 35 23 32 9 26 5 27 13 28 2 37 28 13 7 26 1 27 42 6 36 39 20 31 5 36 39 30 14 20 31 4 39 3 21 35 39 37 19 37 29 1 30 15 39 5 39 7 22 12 23 5 14 10 14 13 3 32 5 38 18 39 36 8 42 13 20 5 12 24 31 20 10 14 2 5 16 1 33 3 33 35 1 22 23 32 15 29 17 28 7 23 16 10 6 8 27 11 15 42 7 26 38 16 39 14 31 25 21 25 14 17 8 18 37 42 37 21 1 10 29 18 39 16 3 14 16 33 24 19 13 24 32 39 37 21 11 5 22 11 14 26 19 30 32 10 39 27 39 16 19 17 6 25 20 38 40 20 5 42 39 16 13 1 5 28 33 15 6 16 37 31 …
Output: YES

Example 3:

Input: 711 1531 419 509 221 117 589 20 547 18 116 673 68 519 279 416 167 205 677 43 238 699 636 14 498 181 657 258 654 290 131 695 253 26 548 383 331 460 454 597 452 605 324 278 4 9 466 131 253 92 446 600 541 663 41 469 338 224 277 576 471 12 228 72 118 155 689 371 457 192 607 480 61 25 530 86 314 487 381 427 554 302 434 360 628 292 588 409 268 614 324 562 706 144 187 646 415 413 156 700 246 89 121 616 52 264 399 416 63 675 341 56 52 73 499 530 500 42 169 320 686 455 225 457 437 450 129 216 124 95 575 37 617 626 304 173 414 272 427 394 182 111 331 635 503 658 628 553 544 322 689 337 297 564 403 334 664 92 195 79 12 269 342 605 407 592 91 521 613 641 60 209 518 512 64 118 523 163 90 298 305 349 658 615 643 338 10 79 509 448 473 295 88 100 679 230 371 327 116 300 193 116 598 134 426 174 259 257 459…
Output: YES

Constraints:

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

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