CT47301

Maya's roads Circular Route

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Legend says the vault under the indigo vats of Bluehollow opens only for a perfect tally of roads. Maya means to find out. 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 <= 3260; 0 <= m <= 3260.

Example 1:

Input: 545 1813 385 405 446 65 453 45 126 267 237 48 265 15 333 147 426 57 123 391 17 71 72 375 472 230 329 462 276 14 215 480 101 443 152 432 456 30 64 332 300 519 22 390 104 410 54 246 365 5 524 469 273 504 344 261 539 451 470 495 380 363 472 134 51 414 397 517 300 62 247 168 59 259 205 502 30 458 534 226 532 413 545 279 419 527 448 203 52 456 515 220 447 280 327 252 337 471 181 451 517 111 197 73 275 10 440 75 54 200 413 130 425 503 407 98 503 324 129 336 483 270 267 244 125 209 437 502 526 429 208 197 79 37 526 35 12 487 224 156 120 433 456 127 210 190 125 517 366 489 407 299 10 521 139 343 516 523 433 163 327 23 187 422 49 522 231 184 542 271 184 218 17 420 147 516 277 349 245 51 165 163 370 260 61 247 14 78 396 374 139 303 196 168 407 112 52 178 198 419 232 522 182 90 359 132 492 376 202 16…
Output: YES

Example 2:

Input: 2564 1586 1870 923 581 152 1019 2286 1193 955 1374 781 1112 1848 868 1246 1286 1049 349 2418 2493 2287 1908 2250 1484 687 1389 2189 1689 388 2278 1682 859 2202 717 1263 140 2500 1560 419 1159 195 2404 1742 2432 1266 45 500 1247 1346 578 1137 931 791 992 1801 1346 2309 1483 1208 668 229 2 774 2137 2196 1014 1383 2452 566 1649 1132 1879 79 1424 1058 998 1224 1621 1287 368 2221 1810 823 2206 1624 1066 703 2073 1999 934 2296 2029 1800 1507 1482 737 10 285 2261 2045 1021 1799 624 826 2320 2430 847 1084 2530 1748 448 2493 359 2275 1062 1776 1649 70 1665 1357 1742 850 2194 1248 1983 1403 319 1756 1273 1650 488 970 668 1644 1686 68 2552 1971 2460 1875 1796 29 1271 475 462 1759 1874 1998 1966 1396 2099 2061 2129 413 1671 1667 1403 1221 2040 206 1955 634 1451 1427 438 1952 644 2053 1962 1564 355 202…
Output: NO

Example 3:

Input: 16 58 9 8 9 14 4 11 10 4 3 5 2 12 5 2 13 12 2 1 13 11 2 4 13 2 16 7 8 1 16 2 4 13 15 2 5 14 10 12 1 12 7 11 3 15 12 16 14 8 5 10 6 3 6 12 11 8 13 9 10 14 5 15 10 15 12 5 13 14 13 3 11 3 13 1 7 2 12 10 11 2 16 6 2 9 4 1 7 13 8 15 1 10 13 10 12 2 6 7 1 8 14 12 3 1 11 7 16 1 4 9 7 8 10 1 9 2
Output: YES

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Maya's roads Circular Route - MEDIUM Coding Problem | CodeTikki