CT36832

The Circular Route of the Woven corridors

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

At the valley of Misthollow, Varun records each corridors in a worn leather ledger. The guild wants answers, not guesses. 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 <= 3131; 0 <= m <= 3131.

Example 1:

Input: 509 1152 109 200 22 158 492 480 92 281 53 100 202 65 247 395 231 426 146 213 180 304 220 22 204 353 83 369 310 102 282 156 447 28 116 323 195 12 290 269 72 13 354 103 198 382 164 156 346 107 194 329 317 469 377 183 14 417 55 465 424 318 168 408 2 337 316 201 304 68 464 301 74 317 356 420 47 504 71 308 13 92 160 46 26 112 80 422 10 383 366 176 213 299 339 367 385 236 267 98 105 107 101 215 64 225 308 506 16 302 362 312 206 389 319 292 336 190 468 175 412 163 504 444 161 397 302 339 281 197 190 173 194 223 75 299 395 190 19 31 304 469 2 281 304 94 360 400 354 241 220 267 375 241 386 154 352 173 450 86 209 387 427 115 449 124 446 268 260 327 363 304 125 22 82 295 66 267 220 482 393 118 41 384 62 127 9 488 471 355 27 72 470 230 236 380 408 439 305 159 234 75 450 284 207 22 278 98 202 225 341 2…
Output: YES

Example 2:

Input: 1548 463 320 177 768 735 415 223 752 672 282 187 137 377 557 1332 943 779 707 1112 488 496 1419 500 282 986 1428 204 601 1021 237 159 1156 251 993 1529 782 1375 1281 918 146 915 1412 1214 1535 1241 437 435 1272 1061 1063 49 813 590 586 442 271 1414 1087 305 1063 1073 53 589 1351 76 1356 1481 90 1387 151 525 503 1196 1339 1260 1380 410 834 1070 904 878 1456 1244 1285 1308 1200 1237 645 1529 250 165 1453 634 1360 296 556 1471 331 772 109 218 251 1380 1008 546 125 1331 95 18 116 85 1093 1266 1114 938 434 130 321 642 329 1128 799 695 1222 831 874 708 311 152 1031 338 427 566 1533 1240 1295 859 948 297 1060 603 369 1001 1197 202 492 41 824 615 98 873 281 1360 575 1179 180 192 31 917 1216 954 703 1032 906 687 1012 664 1432 1104 505 171 726 1354 545 1189 503 395 564 1074 1311 1006 1166 544 1283 5…
Output: NO

Example 3:

Input: 1881 1312 1189 26 1429 1278 1582 1255 878 1799 1314 857 1170 629 275 1396 1334 235 1045 755 1805 1612 9 919 382 1576 1717 668 1390 589 504 352 762 1075 771 1357 626 1594 971 639 492 1768 730 1073 131 1681 1531 198 1051 899 1272 1437 286 112 606 907 437 344 1007 1832 907 1860 201 666 849 1850 1672 649 446 1613 241 1506 872 43 1580 988 1715 437 255 1776 1228 649 757 1738 1165 374 1006 1040 1511 804 700 46 354 217 398 1695 31 817 709 550 528 1780 1343 1277 1032 971 1382 1171 1844 139 1362 271 701 651 1745 148 865 1151 1219 819 908 1594 1634 1847 1675 273 1589 1259 77 317 1418 1216 433 10 1716 1733 336 897 1686 753 559 165 688 1010 114 1224 102 1473 1590 168 809 1156 1569 1516 898 45 1451 256 1048 924 235 676 352 261 421 671 1351 35 1040 811 870 1593 1626 300 872 1785 606 829 1014 1287 1759 16…
Output: YES

Constraints:

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

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