CT50960

The Wild routes of Archivist

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

At the eel marshes of Slitherwick, Archivist records each routes 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 <= 1444; 0 <= m <= 1444.

Example 1:

Input: 1384 365 749 777 876 172 516 321 1157 555 342 1379 1026 1118 255 201 988 1220 125 540 997 224 1000 825 58 1000 87 1300 1344 1379 1023 736 698 1182 924 26 1185 784 510 707 119 990 1017 727 33 842 770 1039 1142 228 237 1112 10 70 579 1265 832 844 72 457 1254 472 1248 193 1108 272 529 871 1060 793 332 776 931 533 637 652 526 14 1162 804 169 34 715 1293 150 1099 868 1271 1257 218 1102 308 1001 1312 534 1018 94 924 853 644 1136 410 1004 1326 297 420 696 629 206 451 863 1248 965 1229 519 1194 1276 455 143 682 403 1050 549 762 755 1354 1119 311 162 95 438 622 863 1044 1248 1326 639 1125 637 1054 990 776 94 905 718 119 1007 984 256 190 767 6 820 597 833 852 884 1168 1147 332 1353 924 1078 572 291 681 22 24 294 168 150 633 1172 1118 718 642 510 76 284 204 1186 663 461 784 48 173 304 45 572 72 262 6…
Output: NO

Example 2:

Input: 228 493 89 220 73 187 57 145 51 3 135 38 196 173 87 56 207 134 146 124 159 71 9 124 13 4 153 207 28 80 184 186 84 208 180 190 164 116 43 171 208 154 58 32 147 44 95 46 103 35 156 101 112 19 25 97 137 67 119 185 218 36 122 224 106 23 202 142 4 149 140 198 109 123 204 61 72 129 163 115 66 204 142 64 148 119 92 69 25 10 204 37 68 184 24 54 23 155 190 191 212 192 217 220 132 6 217 70 139 104 148 222 26 227 85 173 56 68 132 115 79 158 124 199 120 203 220 145 3 112 157 111 72 114 103 212 117 60 202 97 107 225 24 133 186 1 219 223 48 38 2 69 152 67 167 160 154 14 75 15 165 183 93 81 89 124 108 106 97 18 208 16 18 204 214 154 184 75 178 30 136 64 156 153 68 86 219 168 142 99 23 226 212 19 145 134 29 21 189 204 116 34 98 63 139 87 221 43 219 81 71 200 11 220 13 25 78 206 172 123 188 28 100 32 28 21…
Output: YES

Example 3:

Input: 250 543 167 250 104 225 64 41 229 39 161 42 36 65 154 28 248 73 172 171 8 200 55 131 115 201 213 9 43 220 73 72 103 33 140 64 184 10 159 207 100 213 190 204 126 221 62 10 88 212 249 81 124 153 225 60 193 19 166 212 77 210 160 4 146 33 104 218 115 16 148 133 88 34 218 176 87 21 25 88 185 170 50 219 98 119 219 116 207 94 86 118 101 14 50 44 123 72 222 20 219 109 39 119 206 160 235 149 248 128 134 176 88 89 206 67 225 143 105 3 135 203 141 160 134 165 28 116 16 44 102 196 74 120 113 171 118 152 221 86 211 60 34 183 11 177 117 193 170 89 154 114 78 40 55 188 166 155 100 70 232 134 125 170 68 61 201 229 63 48 71 156 183 80 35 220 224 65 162 25 68 33 136 243 35 40 246 95 92 32 191 190 35 200 135 190 104 48 223 228 219 30 93 225 173 7 34 174 95 167 112 226 146 6 57 165 177 68 249 152 2 34 38 58 2…
Output: YES

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Wild routes of Archivist - MEDIUM Coding Problem | CodeTikki