CT48060

Mira's Ruby Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

It is audit day at the poppy fields of Scarlet Plain. Mira spreads the tunnels records across the table and picks up a sharp pencil. 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 <= 2528; 0 <= m <= 2528.

Example 1:

Input: 1858 617 1694 1109 1157 1694 1420 1739 1555 411 429 238 920 891 1631 268 363 382 212 1313 1058 1787 1614 965 386 1752 68 497 1551 241 912 1274 1253 1632 727 87 183 80 353 902 611 1544 1147 1826 198 1599 361 885 1685 1007 52 1344 378 1830 1266 1510 746 1499 1132 286 1355 593 1755 1361 1791 847 1031 636 1190 105 819 1582 1701 877 1637 700 697 395 1857 254 200 1420 1236 530 1546 969 1534 590 1487 1641 1355 206 1224 845 1536 905 1308 113 1558 408 1389 1564 1471 287 409 1438 1833 894 559 1776 1823 727 936 629 720 1024 1711 1399 1538 916 181 1607 1549 1711 845 535 1508 1469 1238 115 98 836 1138 891 267 697 209 161 751 1562 1303 1522 1617 908 398 1465 319 1766 1379 1673 1564 24 92 1562 263 212 378 933 888 417 1220 841 375 1781 1226 841 1189 1648 708 1132 771 1755 1834 921 1323 1399 790 723 69 913…
Output: NO

Example 2:

Input: 499 1620 182 177 496 250 173 489 132 218 301 343 2 132 193 440 433 90 385 243 140 405 271 210 488 316 315 141 125 275 42 377 353 443 117 86 53 331 430 494 38 150 329 276 411 456 377 76 440 187 302 267 442 9 258 313 64 264 496 70 235 201 457 465 190 352 251 166 498 26 100 165 212 333 2 372 196 279 328 464 100 268 57 294 429 46 442 257 105 13 28 421 65 13 284 442 311 235 36 313 85 323 394 431 326 63 327 149 183 37 170 370 353 16 350 43 66 29 374 79 293 291 185 376 109 258 370 464 171 47 295 166 305 137 100 460 379 321 201 180 125 413 385 1 72 335 408 403 55 161 97 404 388 72 27 97 445 290 88 187 126 128 105 300 428 369 310 396 175 243 121 377 320 455 479 409 10 129 191 271 56 228 313 478 166 65 102 51 48 492 267 478 177 485 488 217 37 337 41 4 307 326 76 493 315 423 19 28 72 29 270 290 262 2…
Output: YES

Example 3:

Input: 592 725 562 193 364 268 145 262 206 318 195 78 181 559 193 306 374 19 74 218 414 18 415 250 71 129 490 203 110 361 176 100 590 382 102 262 63 397 251 285 298 359 169 505 550 413 13 418 376 8 443 196 216 464 591 167 457 251 226 170 426 121 215 37 410 247 430 183 456 377 32 352 138 206 156 114 126 170 132 170 454 495 186 496 418 362 225 495 457 123 162 350 480 358 84 536 6 281 333 188 329 248 231 376 93 149 467 136 230 435 550 437 320 305 383 186 180 350 12 570 287 296 148 119 478 143 175 310 550 377 19 273 141 585 511 580 185 151 160 500 30 97 102 473 529 414 523 343 351 74 359 575 245 305 448 432 139 237 149 397 336 255 157 293 110 587 340 266 320 249 99 145 161 303 310 246 9 277 505 311 274 273 502 123 463 498 116 60 419 108 90 196 15 324 295 429 285 265 42 208 168 57 341 291 383 175 278 …
Output: YES

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Mira's Ruby Ledger - MEDIUM Coding Problem | CodeTikki