CT44617

Last roads of Kael

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The chronicler Kael has been asked to verify the safety inspections. On the desk lies a long table of roads 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 <= 2793; 0 <= m <= 2793.

Example 1:

Input: 2558 1688 2454 1285 1021 1558 389 2066 2175 54 1046 326 660 113 1389 2090 2552 2329 890 464 352 2120 1313 1247 807 1617 1237 2149 806 1121 1786 252 2137 870 522 1423 56 1740 86 1935 2176 1022 2020 707 800 2271 1421 538 395 1842 696 944 1356 437 2232 1380 881 1221 232 310 2466 555 1488 849 561 42 1370 400 2436 2057 1349 1307 1123 1071 2173 55 1389 2368 498 372 366 1083 499 1474 433 55 1367 993 1193 1832 1571 2394 929 1740 873 2543 664 1769 232 2537 885 2349 1511 1448 2281 496 2187 316 466 34 1172 734 1201 524 1110 1843 810 2108 1344 1877 1643 2394 1119 2313 854 711 2053 515 2463 1734 2182 763 1019 1744 2472 1314 800 1940 413 1508 2310 1555 1365 1812 213 1901 15 2299 1389 252 916 620 331 1262 421 176 1279 3 580 221 2051 43 415 1460 1509 1640 2164 2466 682 1557 1092 1700 1194 1604 138 1361 93…
Output: NO

Example 2:

Input: 763 1465 183 601 137 524 428 147 326 378 292 373 37 85 164 507 199 690 300 316 553 263 259 572 616 38 713 503 248 371 50 276 552 22 654 336 729 629 656 212 665 178 215 411 95 152 615 392 349 503 10 422 709 454 546 281 672 531 4 680 659 629 40 625 763 637 675 568 252 91 404 226 138 729 493 314 595 388 222 172 500 613 391 392 522 338 326 548 376 313 466 515 89 210 252 348 198 3 95 717 536 250 471 57 301 150 278 390 356 446 385 278 314 713 91 483 420 232 259 629 718 249 355 292 193 738 47 575 227 507 659 582 163 248 391 325 650 627 437 159 273 85 525 516 568 447 178 306 648 311 501 32 65 202 583 573 65 238 283 117 269 46 348 633 582 588 645 519 45 273 276 388 85 525 359 484 660 188 94 245 329 536 205 687 18 121 112 273 329 242 577 711 214 75 466 562 32 320 515 236 361 449 718 510 151 286 309 …
Output: YES

Example 3:

Input: 2704 627 713 282 2415 570 1372 1737 1967 2163 74 662 368 1380 1553 1120 1543 907 1040 896 1510 1944 2546 1759 737 167 1818 1617 394 248 654 838 1824 912 1381 993 402 1260 714 68 1590 708 1028 2484 2509 1239 171 1484 2181 25 525 2354 1484 749 2187 2661 2403 349 354 2552 2266 615 2687 1204 843 59 2020 1730 533 529 2580 519 2694 392 1961 2270 11 145 290 162 1447 1649 1027 517 301 484 2687 2146 1820 2356 2027 962 469 2435 1029 304 825 379 1492 2065 724 2526 2543 622 1380 166 617 646 1224 1741 389 2244 1936 1414 362 1948 814 130 154 464 1423 1173 344 607 1855 2414 1287 1772 560 909 1487 2101 1024 2011 309 831 1838 1754 2688 844 39 139 2040 2424 1778 2287 1378 2639 2648 2199 2614 2218 2499 1728 1459 2415 19 1553 1086 172 1510 2430 1401 1742 1235 2678 2607 1216 1407 2683 1979 925 2311 1255 2621 5…
Output: NO

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Last roads of Kael - MEDIUM Coding Problem | CodeTikki