CT50287

The Circular Route Beneath Alabast

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Dora found an old ledger of bridges in the lighthouse attic at the ivory gates of Alabast. The margin notes pose a precise question. 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 <= 2088; 0 <= m <= 2088.

Example 1:

Input: 646 606 61 403 333 559 487 518 22 211 458 105 24 291 566 472 394 346 198 579 24 553 468 59 513 588 349 331 424 360 487 495 422 160 381 363 153 162 44 236 11 393 46 30 267 569 390 603 399 645 610 334 165 217 548 580 64 161 417 191 190 272 166 98 620 421 265 214 410 302 542 18 12 309 335 91 524 538 644 453 580 520 456 375 237 360 233 10 231 102 4 13 70 605 367 595 575 394 162 131 226 441 543 328 597 175 474 476 108 328 35 145 104 477 80 586 562 572 572 520 601 202 371 432 430 167 265 314 489 248 11 355 553 347 171 634 321 388 145 365 626 58 100 218 416 603 474 371 338 634 394 295 407 178 244 524 575 507 124 214 393 413 308 598 517 393 344 548 349 530 510 577 465 398 207 190 225 455 39 21 19 45 439 306 31 404 628 95 87 133 343 603 66 485 494 113 241 324 58 328 404 19 150 432 272 421 409 355 1…
Output: YES

Example 2:

Input: 1378 1054 1110 967 907 142 56 813 88 401 32 530 239 839 719 11 644 466 1088 543 396 645 1090 1220 1159 921 432 1094 1353 1124 480 604 650 1340 577 319 1276 1054 906 215 722 531 750 207 1143 372 229 90 104 688 302 98 849 1186 830 1315 108 313 125 623 317 696 1339 469 155 355 1208 160 1048 947 724 70 455 862 459 889 221 95 842 453 674 548 82 351 425 1368 73 827 568 1223 869 296 1027 439 656 1146 239 641 471 788 757 999 416 371 812 745 343 564 1062 826 320 966 640 687 207 751 232 481 1254 197 871 179 413 1016 831 863 704 226 1028 384 784 1149 922 332 732 623 320 172 1340 996 539 1251 1163 959 135 1216 1333 342 392 783 1194 188 1098 722 418 1192 847 976 933 389 240 885 540 683 1171 1349 1156 1243 374 133 1015 1342 1130 819 535 1008 874 748 512 811 495 224 692 363 159 678 766 565 869 929 905 80…
Output: YES

Example 3:

Input: 720 470 141 86 710 481 631 39 318 346 69 35 518 360 561 633 519 130 606 501 419 378 322 496 352 47 621 361 90 341 436 563 124 109 508 169 354 265 578 637 344 563 18 440 543 383 118 70 121 698 185 204 388 448 88 684 184 267 376 116 93 591 552 472 78 220 296 508 52 404 311 253 489 409 518 590 109 178 31 426 482 456 14 491 250 272 532 246 709 710 713 459 68 378 544 53 385 7 153 599 51 184 357 347 571 574 73 234 597 76 311 638 24 380 286 711 491 115 281 98 315 583 595 278 222 576 583 455 342 407 267 668 416 54 62 560 581 536 568 475 408 675 511 174 346 196 666 419 303 250 72 465 216 248 244 259 675 277 191 410 1 421 228 34 70 671 156 221 2 234 429 123 650 91 13 663 128 483 296 188 273 702 274 415 32 48 569 610 711 9 480 217 86 432 196 74 167 133 147 90 487 292 443 319 267 427 280 603 335 593 2…
Output: NO

Constraints:

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

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