CT51959

The canals at Silkmead

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Lakshya the chronicler watches over the mulberry rows of Silkmead's stores of canals. A careful computation stands between order and chaos. 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 <= 1784; 0 <= m <= 1784.

Example 1:

Input: 543 1338 489 458 204 460 7 193 70 413 318 436 524 353 337 170 159 513 168 265 26 68 439 217 333 505 131 275 237 352 380 197 392 372 456 181 472 280 490 45 322 82 135 185 521 89 162 384 134 9 23 498 272 285 510 286 249 536 490 463 374 358 482 150 56 524 364 95 119 111 469 394 353 147 237 124 226 237 139 485 495 386 392 339 420 143 149 226 229 212 35 95 510 118 21 472 203 494 52 198 422 470 227 308 116 73 182 98 30 130 358 334 121 62 336 297 265 365 440 211 35 265 280 22 150 143 10 249 304 27 183 210 224 118 415 272 539 320 287 131 160 403 541 182 418 266 481 121 416 85 273 35 400 397 220 69 259 231 172 55 232 142 486 252 154 266 347 306 358 262 270 104 316 521 511 522 140 457 203 281 133 27 244 4 382 91 166 196 292 509 423 129 371 176 73 466 521 69 221 183 34 110 74 356 167 442 41 442 406 7…
Output: YES

Example 2:

Input: 1131 1071 211 334 726 364 328 367 268 1052 258 831 878 1024 937 976 249 322 720 608 594 389 1 1052 885 169 61 214 980 520 128 25 565 927 1119 980 323 101 413 1122 371 564 11 1023 156 320 970 229 603 882 871 242 354 677 269 191 423 784 1037 627 1043 1115 978 279 379 73 999 593 924 257 228 591 385 754 572 161 646 708 130 836 638 1055 940 893 597 77 1084 703 492 60 853 338 520 1058 1116 84 589 105 442 1129 574 236 755 71 1059 94 337 37 881 538 1093 579 184 774 250 245 702 748 886 502 294 359 1088 384 876 382 404 887 552 749 721 855 795 1088 551 1096 770 1080 728 564 1083 841 1099 987 18 154 880 975 731 478 394 90 1070 56 136 139 648 867 973 1129 715 199 546 96 876 1012 67 487 865 178 518 340 478 553 638 164 606 793 977 584 281 700 42 277 851 637 598 64 401 552 339 119 505 305 93 869 676 749 4…
Output: NO

Example 3:

Input: 1317 884 457 278 514 1241 347 880 107 171 148 1070 1260 1236 638 656 1305 1036 63 264 1059 1267 1184 824 777 135 980 1315 584 434 548 1179 872 1154 538 327 1312 190 361 36 461 232 863 886 74 1281 1172 769 107 179 638 893 1226 255 1019 160 955 458 190 618 193 34 1119 874 773 1150 876 40 569 1216 708 15 1000 242 535 151 275 421 284 674 558 1245 96 636 254 432 1163 10 1312 790 96 435 83 284 503 1114 496 900 237 160 1101 665 1133 523 660 480 98 163 954 628 501 1029 807 1231 73 559 829 984 297 602 1048 1217 318 660 367 514 431 41 552 211 1261 1144 527 768 935 1042 559 237 590 705 337 926 777 313 1187 1042 929 372 1294 819 1291 1176 987 1233 1147 228 764 399 226 479 35 369 932 53 617 705 165 1077 657 643 185 398 847 343 262 418 292 1244 827 573 1124 1218 959 867 656 992 236 1064 938 577 384 597 …
Output: YES

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The canals at Silkmead - MEDIUM Coding Problem | CodeTikki