CT41021

Gleaming canals Circular Route

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Every season at the coastal hub of Tidewater, someone must certify the cargo before shipping. This year the task falls to Chetan, armed only with the canals register. 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 <= 3916; 0 <= m <= 3916.

Example 1:

Input: 1759 613 875 851 648 1210 807 30 42 923 851 1128 1580 1066 474 1421 1446 535 339 1667 516 1123 115 111 583 823 741 127 1642 237 103 57 257 1037 98 310 1183 231 1604 1016 14 1684 1400 632 739 1015 1148 1667 1571 40 1252 1268 1727 443 678 1451 1587 601 733 238 1677 443 1655 405 564 1119 1295 334 351 452 255 6 538 577 270 926 583 1102 1449 516 94 143 1282 1083 1497 1039 1173 398 1434 1177 756 1648 990 922 843 1599 275 830 883 480 757 755 380 1222 156 1233 1556 770 1606 820 1001 1730 1191 1243 1051 1116 1397 1710 897 1393 995 1442 89 1062 1611 1018 736 1227 930 158 40 778 568 648 849 1720 1325 154 1553 512 1132 1055 92 1464 374 717 515 287 1565 477 1186 191 958 775 1037 886 748 1537 979 559 751 977 1166 793 1188 1692 1005 323 1554 435 1052 1020 1192 1389 663 1340 125 773 1612 717 640 1755 708 …
Output: NO

Example 2:

Input: 2343 1783 114 1386 2164 1620 750 817 215 1302 1642 2157 1325 1054 326 1422 582 2206 2158 2014 1988 685 1955 1399 2314 2189 546 113 1351 56 85 610 529 2148 13 952 1121 725 571 1937 393 2142 2046 1812 1182 1590 2298 859 1245 1928 1436 2133 2136 1842 620 962 1189 109 649 1024 208 2289 1711 161 2230 321 1107 933 2090 1841 611 888 2026 727 1315 1559 1591 579 2151 2069 789 1815 290 982 896 170 2045 1660 385 2306 916 345 147 1040 591 902 1786 1726 2333 172 667 241 1067 600 2312 535 1427 579 1645 781 680 350 2214 962 639 1023 1215 448 264 818 900 766 487 2343 1119 1447 451 1717 522 1208 179 509 291 715 1503 2159 1858 1650 405 99 292 60 1855 67 1103 410 1884 1046 115 238 248 2335 1576 511 210 358 2278 1257 1246 2172 869 1697 247 2071 2146 1758 1365 2332 78 834 1548 1766 2216 305 1347 1797 757 474 8…
Output: NO

Example 3:

Input: 566 2364 496 499 318 104 430 26 257 85 121 495 495 384 274 301 51 68 559 437 407 411 219 305 457 47 386 456 408 373 537 455 333 387 387 61 421 324 407 388 439 421 525 323 552 209 340 223 284 52 106 271 517 439 242 100 491 474 161 372 336 61 2 190 482 33 543 151 271 333 509 332 144 4 391 488 223 405 48 256 280 160 33 454 135 421 430 169 545 54 200 219 191 147 555 114 296 37 430 392 266 406 44 528 271 231 352 56 208 83 421 367 377 217 29 299 194 228 249 230 4 418 430 279 476 293 409 117 386 410 178 318 457 435 492 459 354 204 453 109 522 67 76 242 284 212 158 20 22 520 184 473 41 486 210 563 279 115 172 344 437 551 168 502 354 298 196 464 310 513 300 506 186 418 201 84 488 450 276 60 463 277 309 268 422 296 192 96 52 342 19 168 58 9 509 439 297 222 412 546 477 65 319 199 487 231 513 218 111 …
Output: YES

Constraints:

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

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