This commit is contained in:
Zengtudor 2025-07-15 10:55:36 +08:00
parent 72952d982b
commit c483494ac5
9 changed files with 1109 additions and 0 deletions

56
src/7/15/U306735.cpp Normal file
View File

@ -0,0 +1,56 @@
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <istream>
#include <map>
#include <string>
#include <vector>
using ll=int64_t;
ll n{},m{};
std::string s;
std::vector<std::vector<ll>> edge;
ll find(ll now,std::map<char, ll> &w,ll max,std::vector<bool> &vis){
if(vis[now]){
return -1;
}
vis[now]=true;
w[s[now]]++;
max=std::max(max,w[s[now]]);
for(ll nxt:edge[now]){
if(ll findr = find(nxt, w,max,vis);findr==-1){
return -1;
}else{
max=std::max(max,findr);
}
}
w[s[now]]--;
vis[now]=false;
return max;
}
int main(){
std::iostream::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
std::cin>>n>>m;
edge.resize(n+1);
std::cin>>s;
s=' '+s;
for(ll i=1;i<=m;i++){
ll u{},v{};
std::cin>>u>>v;
edge[u].push_back(v);
}
for(ll i=1;i<=n;i++){
ll ans{};
std::map<char, ll> w;
std::vector<bool> vis(n+1);
ans=find(i, w, 0,vis);
std::cout<<ans<<'\n';
}
}

5
src/7/15/opt1.ans Normal file
View File

@ -0,0 +1,5 @@
3
1
2
1
1

6
src/7/15/opt1.in Normal file
View File

@ -0,0 +1,6 @@
5 4
abaca
1 2
1 3
3 4
4 5

6
src/7/15/opt2.ans Normal file
View File

@ -0,0 +1,6 @@
-1
-1
-1
-1
-1
-1

8
src/7/15/opt2.in Normal file
View File

@ -0,0 +1,8 @@
6 6
xzyabc
1 2
3 1
2 3
5 4
4 3
6 4

10
src/7/15/opt3.ans Normal file
View File

@ -0,0 +1,10 @@
4
4
2
3
1
2
1
1
1
1

16
src/7/15/opt3.in Normal file
View File

@ -0,0 +1,16 @@
10 14
xzyzyzyzqx
1 2
2 4
3 5
4 5
2 6
6 8
6 5
2 10
3 9
10 9
4 6
1 10
2 8
3 7

500
src/7/15/opt4.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
-1
-1
1
-1
-1
-1
-1
1
1
1
-1
2
-1
1
1
-1
-1
2
1
-1
-1
-1
1
1
1
1
2
1
2
1
1
1
1
1
1
1
-1
2
-1
-1
1
1
-1
-1
-1
1
2
1
-1
1
1
1
-1
1
1
1
-1
1
1
1
-1
1
1
1
-1
1
2
1
2
1
-1
1
-1
-1
1
2

502
src/7/15/opt4.in Normal file
View File

@ -0,0 +1,502 @@
500 500
bbaaeadbdaabaebeaadaccbacddaedbeacebabdcecddccaabeecddaceaeacadaecbacbeaadcaaebadbcedbcadacddacdeabdcbabbabdbabcdcbbabebabdbeedeeaccdcdbcaabcdaedeabaebdcbdcaecbebecdcdeaaeceaabcaeaacedcdcaccdcadabaaabeeacbabacadbabebdbbdcdaeeebbbdedabdebcbdaeccdbcebedbabeedeacbbeabebcecdabbdcbccadcdcddeccdadcdbbccebbbabcdbabeeaccedbccbedbdcabcddcabbcbcaeeeaebeadaebcebabccaccdbeeddddddcddeebeedeeddacbdbcbedccbacddcbeedaedddaeeddcdbdbddbcdcedbebcdaebacdeadabeeceabddbeedaeeedeedeecbebbdddcbbaaaadbbdaddcededbaaabaed
86 345
185 361
431 297
189 276
166 464
5 493
192 449
37 341
129 157
217 481
225 443
471 201
257 149
131 357
159 456
121 439
351 223
297 436
141 205
207 471
431 410
401 101
373 129
477 301
1 481
411 135
327 73
303 31
315 397
496 187
393 314
101 140
246 101
294 37
259 307
350 481
407 283
5 17
108 18
293 145
63 494
305 327
365 474
475 51
161 253
473 149
463 65
425 45
97 440
281 161
300 222
125 271
231 413
481 401
166 261
321 141
150 237
291 125
451 460
333 269
207 233
481 365
251 431
497 133
47 461
497 350
333 164
260 437
46 489
313 481
495 185
169 291
53 396
401 251
440 237
107 201
21 409
463 325
498 359
401 255
315 426
143 23
266 35
479 70
253 157
325 136
32 357
197 73
365 225
23 161
287 246
251 101
469 312
161 26
242 17
444 426
155 29
148 273
3 337
384 224
461 333
103 303
79 482
244 281
477 53
275 255
177 326
41 194
125 201
133 449
61 110
181 101
429 446
25 141
281 496
238 257
97 304
86 70
357 157
238 177
431 245
145 9
124 1
101 411
268 189
301 401
290 105
131 319
159 201
67 281
414 286
47 463
26 446
137 282
357 125
267 273
101 309
94 234
111 63
61 336
411 261
127 18
409 79
389 55
261 87
285 105
445 74
323 322
117 291
264 285
251 167
381 437
73 177
285 161
426 331
489 9
491 352
201 325
397 107
96 301
185 285
181 76
57 26
337 436
321 126
349 241
401 43
321 286
173 23
385 35
329 413
282 357
63 141
259 467
2 320
297 103
301 107
316 281
357 291
461 316
388 461
357 401
121 341
288 101
295 99
493 377
485 101
321 271
186 151
221 91
15 461
356 321
306 460
2 215
321 392
33 264
17 22
206 436
332 197
311 116
369 386
109 65
401 491
299 447
65 177
285 257
323 321
342 461
78 223
142 241
281 241
481 31
247 251
101 186
397 481
153 469
5 55
229 133
285 15
121 445
462 239
252 199
87 1
249 436
461 450
351 196
113 27
389 210
467 495
291 451
173 127
301 363
96 483
27 11
71 429
284 365
116 16
453 309
219 282
405 481
217 457
397 165
1 117
219 51
141 85
461 460
71 125
94 465
277 163
147 313
17 33
249 109
470 269
405 65
210 146
208 171
257 35
134 387
331 185
297 269
381 451
101 48
161 55
226 245
310 314
286 196
21 271
483 28
426 400
297 341
237 141
8 397
324 236
445 113
461 243
281 121
406 342
21 361
468 376
133 137
181 171
1 93
121 111
376 295
442 210
436 329
463 452
299 55
141 21
471 493
395 476
177 365
281 273
43 96
89 345
323 145
281 371
254 23
316 193
45 234
209 101
37 405
76 201
342 209
421 237
219 408
135 346
383 459
61 451
129 5
84 465
1 257
391 193
317 203
37 129
462 319
69 140
27 1
1 276
153 486
441 241
322 165
396 42
349 175
160 400
221 268
91 246
273 247
12 34
416 244
30 61
16 21
93 429
217 312
386 82
81 274
133 405
57 303
321 133
251 119
69 113
121 471
91 436
149 1
477 413
243 492
401 143
90 89
441 221
209 63
165 431
73 37
54 271
379 341
188 442
76 452
481 441
437 96
485 151
312 401
9 166
111 181
189 152
125 119
500 330
289 141
446 425
361 186
241 11
397 201
430 73
9 77
93 439
226 203
289 201
348 201
201 13
405 321
121 351
445 492
291 433
101 25
472 49
5 143
221 51
150 324
269 24
89 469
175 77
109 51
121 73
191 431
373 230
377 488
493 325
110 267
1 103
137 353
136 368
207 261
334 29
119 335
65 16
127 297
71 324
376 247
78 124
285 129
299 218
178 257
177 128
21 221
225 211
463 283
171 181
249 63
33 124
297 5
365 297
68 105
329 193
498 293
33 101
61 79
302 258
289 421
52 266
457 12
111 357
479 374
231 487
339 201
386 2
1 409
211 332
29 211
290 286
363 155
79 77
46 17
91 33
237 158
141 256
327 41
428 429
36 159
391 41
353 397
407 476
106 295
113 121
440 449
253 177
451 415
41 453
441 209
168 194
79 475
462 224
157 423
85 173
61 6
463 81
309 189
464 61
111 433
184 301
30 129
437 13
351 441
414 80
29 45
11 441
331 220
93 284
103 209
425 426
325 45
283 297
157 152
7 429
119 34
149 140
272 41
435 445
106 289
114 493
451 387
61 239
117 129
389 485
113 7
109 275
63 3
231 317
21 117
421 445
207 467
261 49
156 103