CT49134

Yara's corridors Circular Route

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

It is audit day at the thorn maze of Bramblecourt. Yara spreads the corridors records across the table and picks up a sharp pencil. 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 <= 3694; 0 <= m <= 3694.

Example 1:

Input: 2190 3656 1500 1485 669 663 1228 451 1066 1239 1828 128 292 1013 807 273 931 1089 1464 854 312 750 834 1675 1602 1593 892 587 1406 52 1798 827 1067 576 867 1347 80 387 1977 1193 828 990 1397 970 1153 1925 891 595 114 2177 1194 323 457 1858 247 589 334 320 587 1916 869 1741 1535 7 1866 1067 968 1388 874 7 2061 754 1079 140 96 836 1323 615 1857 283 336 988 1891 349 1659 1821 298 186 1282 1788 1300 1487 134 779 1483 491 834 1630 143 1145 571 109 1594 214 393 1939 128 931 667 2085 1515 1707 1954 564 1987 1833 1415 27 1064 1761 623 182 707 31 1330 487 91 491 2079 979 1817 1557 1058 1547 216 1687 1876 1507 263 1940 2139 990 878 1988 223 2128 1988 119 229 1655 1326 1516 768 683 562 2005 2100 1225 1334 1511 1104 1737 1318 1037 1177 1778 1809 973 1541 2108 1535 122 594 1660 264 941 702 1438 1024 18…
Output: YES

Example 2:

Input: 2101 1507 1497 669 1931 575 965 1998 185 504 1893 1591 1098 1981 1664 109 37 233 155 475 757 1161 911 241 713 51 1668 1889 1062 676 1790 938 307 1324 514 156 1382 1996 1028 1394 1389 330 295 944 1642 494 1496 576 1150 1183 1966 250 715 1403 1628 1788 788 2022 1102 1416 647 1333 1031 901 769 1605 428 1552 1999 1265 1974 1255 273 1657 1991 873 1606 124 2039 1156 1139 349 545 299 1122 1981 476 1936 461 892 630 65 37 310 1332 1972 1515 675 315 30 241 1632 1977 687 634 809 1926 1433 23 1096 1695 2008 1832 270 1654 1522 1314 744 1716 284 368 1966 495 687 1125 454 477 1159 733 663 1150 582 807 371 532 1988 1574 25 1938 924 28 1472 2049 734 1310 990 1804 1649 1480 456 181 910 1758 816 1851 908 1823 2051 997 1815 1312 306 432 84 365 2059 1330 1443 1967 712 1518 1058 1308 1401 1334 580 593 1260 1734…
Output: YES

Example 3:

Input: 522 372 373 12 289 314 349 327 161 14 153 4 342 146 67 500 424 462 325 93 464 79 69 121 238 433 341 520 255 389 462 48 203 355 97 484 254 403 411 53 390 280 169 335 188 129 41 223 237 347 187 358 10 216 433 447 522 27 344 243 303 207 133 41 389 7 231 21 329 409 88 500 443 449 480 496 163 258 96 90 452 107 159 274 444 329 427 266 292 23 359 490 18 513 307 451 126 472 100 419 474 358 390 328 314 313 68 111 103 437 233 53 83 376 447 402 263 521 247 508 101 514 373 182 354 331 317 493 479 151 306 232 17 161 428 232 453 500 144 289 49 343 40 192 232 320 337 431 368 92 187 51 505 213 520 285 54 170 321 210 14 501 288 436 11 42 108 325 374 215 375 354 508 192 11 48 151 417 4 454 414 274 165 491 140 138 174 315 225 365 267 162 312 422 6 353 324 276 321 123 84 332 264 460 114 238 346 57 19 423 159 …
Output: YES

Constraints:

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

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