CT49901

Sona's canals Reckoning

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The harbor bell rings at the moonlit lagoon of Selene; Sona weighs the day's canals manifests and starts the calculations. 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 <= 1757; 0 <= m <= 1757.

Example 1:

Input: 315 1548 17 278 168 26 273 151 9 86 76 171 289 202 14 127 115 95 74 9 113 16 113 92 222 202 130 150 290 89 106 159 270 202 171 59 188 214 311 38 77 9 22 241 94 115 103 202 137 143 57 290 292 49 137 93 124 157 251 105 210 282 90 53 287 224 261 78 273 260 87 13 182 29 19 109 244 88 294 203 115 30 89 244 69 108 180 172 168 119 160 153 98 72 235 175 191 192 107 12 186 105 245 241 90 167 194 94 251 98 210 96 66 247 18 112 62 226 232 109 273 137 201 304 5 291 217 9 239 196 243 302 111 222 238 252 205 179 314 97 161 307 275 43 51 259 60 69 161 201 72 315 298 194 66 199 287 293 20 177 66 183 158 229 178 45 298 193 10 214 106 301 12 170 218 50 213 61 203 197 21 38 99 222 173 28 78 6 17 65 274 315 88 300 82 119 54 123 194 267 83 259 255 157 115 141 195 28 81 171 139 215 123 72 116 135 88 29 178 103 …
Output: YES

Example 2:

Input: 533 985 431 66 199 82 355 120 266 10 493 141 348 228 25 393 433 390 170 88 174 517 175 413 462 213 3 419 40 382 109 372 128 503 325 532 101 350 508 353 148 512 312 120 464 252 264 99 14 172 418 157 46 473 71 385 337 88 80 533 526 467 123 221 380 146 495 531 243 327 506 135 164 163 276 240 438 469 306 96 394 161 316 147 6 353 10 341 30 257 530 525 450 171 132 421 203 415 355 326 405 33 238 290 290 311 305 247 217 46 39 450 92 432 107 97 186 333 273 386 188 102 204 491 321 181 83 417 118 396 410 387 145 44 512 201 92 294 305 239 145 418 364 11 432 443 470 392 230 185 360 251 291 77 98 175 77 69 493 232 157 501 382 29 361 340 441 512 42 259 135 41 404 327 87 377 42 256 175 520 195 295 29 108 165 360 376 102 13 190 111 505 51 247 118 393 108 369 485 468 486 509 74 259 500 402 367 458 345 390 1…
Output: YES

Example 3:

Input: 1143 554 712 920 320 722 42 66 111 744 199 882 511 284 878 582 318 281 53 582 212 33 251 990 1012 734 1049 751 215 826 716 483 791 171 823 804 824 55 366 898 820 884 663 257 902 284 894 812 68 1035 1076 762 339 615 975 650 334 121 921 995 815 1001 1061 300 942 880 837 92 473 549 132 141 455 205 162 193 535 646 242 102 163 999 247 371 445 1106 236 894 643 361 601 1087 100 271 1028 783 466 221 549 1009 666 584 806 951 751 142 1111 692 813 1120 525 412 351 1059 188 58 410 1126 620 767 297 524 764 220 1120 588 73 568 1081 367 1021 1065 73 294 541 726 144 959 1091 495 922 949 184 601 917 908 148 600 37 1087 226 912 776 464 176 992 437 288 748 298 859 904 1023 191 973 749 847 996 654 761 1113 271 450 959 975 1007 529 376 1121 504 573 65 748 90 817 935 992 49 681 783 859 137 939 210 8 889 490 793…
Output: NO

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Sona's canals Reckoning - MEDIUM Coding Problem | CodeTikki