QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#105655#6402. MEXimum Spanning TreezhouhuanyiRE 2000ms3780kbC++112.3kb2023-05-14 17:25:072023-05-14 17:25:08

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-14 17:25:08]
  • 评测
  • 测评结果:RE
  • 用时:2000ms
  • 内存:3780kb
  • [2023-05-14 17:25:07]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<cassert>
#define N 2000
using namespace std;
int read()
{
    char c=0;
    int sum=0;
    while (c<'0'||c>'9') c=getchar();
    while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
    return sum;
}
int n,m,d,s,t,len,rt[N+1],pv[N+1],X[N+1],Y[N+1],Z[N+1],cnt[N+1];
bool used[N+1],vis[N+1],vst[N+1],cl[N+1];
vector<int>E[N+1];
void add(int x,int y)
{
    E[x].push_back(y);
    return;
}
int find(int x)
{
    if (rt[x]==x) return x;
    return rt[x]=find(rt[x]);
}
void unionn(int x,int y)
{
    rt[x]=y;
    return;
}
void add_edge()
{
    for (int i=s;i<=t;++i) pv[i]=0,E[i].clear();
    for (int i=0;i<=m;++i) vst[i]=(i>d);
    for (int i=1;i<=m;++i) cl[i]=0;
    for (int i=1;i<=n;++i) rt[i]=i;
    for (int i=1;i<=m;++i)
	if (used[i])
	{
	    vst[Z[i]]=1;
	    if (find(X[i])!=find(Y[i])) unionn(find(X[i]),find(Y[i]));
	}
    for (int i=1;i<=m;++i)
	if (!used[i])
	{
	    if (!vst[Z[i]]) add(s,i);
	    if (find(X[i])!=find(Y[i])) cl[i]=1,add(i,t);
	}
    for (int i=1;i<=m;++i)
	if (used[i])
	{
	    for (int j=1;j<=n;++j) rt[j]=j;
	    for (int j=1;j<=m;++j)
		if (used[j]&&find(X[j])!=find(Y[j])&&j!=i)
		    unionn(find(X[j]),find(Y[j]));
	    for (int j=1;j<=m;++j)
		if (!used[j])
		{
		    if (Z[i]==Z[j]) add(i,j);
		    if (!cl[j]&&find(X[j])!=find(Y[j])) add(j,i);
		}
	}
    return;
}
bool find_rd()
{
    int top;
    queue<int>q;
    for (int i=s;i<=t;++i) vis[i]=0;
    q.push(s),vis[s]=1;
    while (!q.empty())
    {
	top=q.front(),q.pop();
	for (int i=0;i<E[top].size();++i)
	    if (!vis[E[top][i]])
	    {
		vis[E[top][i]]=1,pv[E[top][i]]=top,q.push(E[top][i]);
		if (E[top][i]==t) return 1;
	    }
    }
    return 0;
}
void solve()
{
    int x=pv[t];
    while (x!=s) used[x]^=1,x=pv[x];
    return;
}
bool check(int x)
{
    d=x,add_edge();
    if (!find_rd()) return 0;
    bool op=0;
    for (int i=1;i<=m;++i) op|=(Z[i]==x);
    assert(op);
    solve();
    return 1;
}
int main()
{
    n=read(),m=read(),s=0,t=m+1;
    for (int i=1;i<=m;++i) X[i]=read(),Y[i]=read(),Z[i]=read();
    for (int i=0;i<=m;++i)
	if (!check(i))
	{
	    printf("%d\n",i);
	    return 0;
	}
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3632kb

input:

4 4
1 2 0
2 3 1
1 3 1
3 4 2

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 383ms
memory: 3600kb

input:

1000 1000
647 790 6
91 461 435
90 72 74
403 81 240
893 925 395
817 345 136
88 71 821
831 962 53
164 270 298
14 550 317
99 580 81
26 477 488
977 474 861
413 483 167
872 675 17
819 327 449
594 242 68
381 983 319
867 582 358
869 225 669
274 352 392
40 388 998
246 477 44
508 979 286
483 776 71
580 438 6...

output:

502

result:

ok 1 number(s): "502"

Test #3:

score: 0
Accepted
time: 1188ms
memory: 3660kb

input:

900 1000
232 890 107
425 399 19
5 74 753
105 333 163
779 42 582
359 647 524
767 409 48
239 780 443
484 489 546
97 634 562
627 866 714
500 357 590
60 728 591
407 686 210
547 32 370
76 772 500
407 584 772
73 699 69
332 847 516
829 754 727
562 756 678
819 303 128
781 667 263
535 672 767
89 762 216
878 ...

output:

801

result:

ok 1 number(s): "801"

Test #4:

score: 0
Accepted
time: 300ms
memory: 3780kb

input:

500 1000
381 118 230
258 331 21
403 71 207
170 2 125
467 99 6
369 100 492
70 187 352
99 163 123
135 51 352
461 175 486
275 194 236
299 14 19
16 1 68
7 229 316
235 433 320
411 179 463
112 329 326
464 169 52
377 93 51
84 336 335
42 240 379
182 496 344
377 481 195
88 286 491
199 425 165
37 292 44
197 2...

output:

403

result:

ok 1 number(s): "403"

Test #5:

score: 0
Accepted
time: 1484ms
memory: 3652kb

input:

900 1000
698 454 775
6 762 755
585 346 86
220 245 253
54 634 184
634 249 234
454 363 546
520 799 501
103 346 134
381 346 792
835 782 614
359 220 485
634 68 54
411 220 439
701 364 791
220 876 15
70 346 317
220 461 769
577 431 117
488 107 706
160 39 864
220 172 721
431 400 556
801 364 716
37 845 83
99...

output:

801

result:

ok 1 number(s): "801"

Test #6:

score: 0
Accepted
time: 300ms
memory: 3716kb

input:

500 1000
7 326 457
269 363 262
414 164 422
416 321 391
37 180 315
304 212 80
483 439 185
221 55 236
456 428 164
401 142 133
42 197 327
366 389 181
125 492 347
220 277 308
316 426 192
29 95 268
50 87 366
62 394 136
480 255 287
363 39 366
489 103 302
477 370 418
16 82 259
374 398 298
77 224 64
402 474...

output:

404

result:

ok 1 number(s): "404"

Test #7:

score: 0
Accepted
time: 1ms
memory: 3628kb

input:

1000 1000
404 572 946
963 590 625
691 563 394
297 369 699
379 667 345
285 219 775
860 851 693
393 962 118
78 19 178
986 466 284
14 709 603
897 698 491
432 875 675
268 886 372
599 1000 151
938 435 978
554 22 577
53 804 686
932 195 192
974 100 267
195 219 790
545 242 669
720 623 317
181 514 48
75 373 ...

output:

1

result:

ok 1 number(s): "1"

Test #8:

score: 0
Accepted
time: 719ms
memory: 3760kb

input:

1000 1000
856 130 621
913 107 385
323 657 942
779 980 628
466 126 230
363 663 577
714 515 741
397 70 459
819 227 31
588 941 524
248 131 529
398 621 657
128 974 220
729 419 300
337 976 204
574 239 122
661 356 49
833 411 778
589 699 181
919 657 458
742 280 270
403 878 5
882 489 3
573 674 954
798 99 29...

output:

667

result:

ok 1 number(s): "667"

Test #9:

score: 0
Accepted
time: 81ms
memory: 3760kb

input:

1000 1000
224 443 706
443 724 126
443 586 793
161 443 52
443 147 450
443 140 390
443 276 715
443 909 189
84 745 544
21 879 174
703 443 353
443 414 332
543 443 141
920 443 154
443 558 384
443 794 212
937 745 536
168 443 119
692 443 736
443 634 268
588 443 752
443 895 740
745 729 209
443 827 996
338 4...

output:

236

result:

ok 1 number(s): "236"

Test #10:

score: 0
Accepted
time: 1304ms
memory: 3736kb

input:

1000 1000
798 241 635
439 138 474
251 966 10
394 250 763
673 724 587
333 150 384
825 333 785
952 923 506
131 333 777
172 754 207
253 172 580
394 496 435
138 578 181
658 289 458
87 241 64
888 729 604
333 638 641
548 966 789
205 138 198
372 966 799
497 333 220
923 412 724
333 347 128
769 138 685
331 3...

output:

791

result:

ok 1 number(s): "791"

Test #11:

score: 0
Accepted
time: 1ms
memory: 3600kb

input:

1000 1000
263 550 562
16 86 168
130 138 878
947 761 527
908 622 222
374 942 114
218 643 282
240 102 639
470 374 651
646 151 538
324 7 710
825 835 307
808 473 577
356 677 15
887 572 558
764 340 18
263 756 365
40 407 162
300 715 469
604 358 23
433 415 579
198 720 930
626 801 869
863 589 300
560 116 40...

output:

19

result:

ok 1 number(s): "19"

Test #12:

score: 0
Accepted
time: 2ms
memory: 3700kb

input:

800 1000
711 767 733
68 352 762
232 36 276
511 777 102
552 332 366
608 135 442
686 184 347
608 281 273
334 427 709
678 385 192
278 527 645
287 285 595
630 409 751
382 665 145
745 330 650
656 31 155
777 25 327
685 212 456
202 132 745
707 163 363
241 421 56
157 510 718
17 734 199
496 157 140
185 422 4...

output:

4

result:

ok 1 number(s): "4"

Test #13:

score: 0
Accepted
time: 1ms
memory: 3600kb

input:

800 1000
774 151 780
578 702 395
739 410 171
566 355 641
559 799 1
682 477 622
666 701 61
329 778 339
236 357 32
605 599 502
459 494 326
465 746 605
34 742 352
161 365 41
5 799 636
505 439 344
36 333 50
780 639 323
18 465 441
459 644 93
668 453 279
442 216 509
585 469 700
390 462 158
191 219 594
457...

output:

6

result:

ok 1 number(s): "6"

Test #14:

score: 0
Accepted
time: 2ms
memory: 3620kb

input:

800 1000
506 646 450
584 83 171
440 107 282
36 582 726
778 159 159
761 203 349
660 26 232
501 160 627
183 300 75
326 658 117
48 639 489
73 690 425
404 313 665
88 15 61
262 103 691
84 297 698
49 298 420
598 243 147
170 139 231
248 545 257
86 632 29
46 339 491
504 538 316
692 3 19
287 134 156
239 462 ...

output:

4

result:

ok 1 number(s): "4"

Test #15:

score: 0
Accepted
time: 2ms
memory: 3676kb

input:

800 1000
163 13 63
14 599 331
465 67 644
411 722 430
245 411 105
764 38 755
411 596 644
667 46 455
599 225 59
475 194 61
744 299 189
599 789 609
436 238 730
706 24 190
543 67 301
527 411 336
431 599 131
599 375 752
797 671 357
46 742 634
46 246 132
530 744 360
513 154 118
664 599 462
408 281 138
599...

output:

2

result:

ok 1 number(s): "2"

Test #16:

score: 0
Accepted
time: 0ms
memory: 3760kb

input:

800 1000
764 362 605
741 635 454
494 8 441
146 747 465
143 38 471
658 73 638
394 766 398
626 692 337
465 271 300
181 122 465
212 104 175
202 663 521
270 435 213
136 202 627
576 370 707
696 206 344
632 766 473
44 612 634
395 6 337
583 25 608
731 144 121
142 540 454
315 777 523
460 570 342
634 138 297...

output:

12

result:

ok 1 number(s): "12"

Test #17:

score: 0
Accepted
time: 3ms
memory: 3740kb

input:

800 1000
203 141 338
184 79 694
396 708 790
790 477 34
743 182 8
71 252 362
149 100 254
321 365 325
270 557 346
797 361 757
8 718 372
21 245 414
489 757 719
160 235 168
346 124 284
645 203 35
535 515 490
83 707 100
464 165 778
49 600 491
445 337 565
602 646 111
578 668 429
353 103 10
478 489 97
185 ...

output:

16

result:

ok 1 number(s): "16"

Test #18:

score: 0
Accepted
time: 2ms
memory: 3620kb

input:

800 1000
564 346 296
375 149 540
106 615 70
574 351 121
205 274 240
93 595 304
205 584 423
564 304 79
205 723 121
138 754 416
574 623 591
644 356 796
480 261 756
553 574 191
205 687 5
352 744 308
109 93 774
76 791 358
375 669 387
485 350 568
92 307 437
655 564 507
268 551 594
772 574 710
437 205 573...

output:

15

result:

ok 1 number(s): "15"

Test #19:

score: 0
Accepted
time: 6ms
memory: 3648kb

input:

800 1000
428 737 331
388 113 132
72 149 479
759 414 599
623 106 593
764 625 515
179 66 167
243 271 778
154 139 590
611 29 630
183 147 753
129 660 745
644 444 295
409 662 42
146 107 463
663 526 63
184 683 534
486 548 106
216 314 304
317 353 237
270 592 229
465 760 541
174 449 0
700 614 632
339 138 27...

output:

53

result:

ok 1 number(s): "53"

Test #20:

score: 0
Accepted
time: 3ms
memory: 3612kb

input:

800 1000
611 663 102
139 241 313
246 110 720
427 303 718
264 728 435
109 194 188
155 564 549
179 143 619
382 402 28
544 474 48
362 772 50
592 792 5
643 592 12
389 578 304
321 649 623
111 757 639
436 558 569
445 369 572
712 252 776
158 712 359
681 96 289
454 271 352
686 178 34
324 221 422
1 369 21
14...

output:

54

result:

ok 1 number(s): "54"

Test #21:

score: 0
Accepted
time: 5ms
memory: 3648kb

input:

800 1000
264 249 496
428 788 667
25 249 366
791 194 325
710 715 227
676 21 429
688 673 619
528 548 60
791 771 438
249 3 793
391 587 234
715 296 446
374 799 441
541 791 200
791 167 365
12 249 1
785 548 309
295 374 47
597 781 430
385 453 7
791 429 83
249 484 796
3 753 563
361 249 582
791 206 277
548 1...

output:

52

result:

ok 1 number(s): "52"

Test #22:

score: 0
Accepted
time: 17ms
memory: 3600kb

input:

800 1000
214 704 283
439 177 321
704 79 514
558 435 609
565 749 263
733 438 98
714 352 65
176 153 434
764 284 184
412 15 11
402 374 265
151 663 790
655 468 496
58 590 719
595 613 760
178 27 193
707 799 430
100 671 31
625 782 704
577 639 650
237 345 101
548 87 686
377 99 628
4 544 179
372 301 584
265...

output:

108

result:

ok 1 number(s): "108"

Test #23:

score: 0
Accepted
time: 13ms
memory: 3700kb

input:

800 1000
116 756 233
618 415 636
234 176 51
640 67 89
717 624 467
150 329 395
471 110 374
681 638 549
355 2 490
333 604 56
481 621 591
348 11 474
362 108 447
610 450 209
50 258 541
161 407 82
178 49 631
691 293 510
21 797 796
414 110 49
43 73 733
695 264 64
444 399 199
677 347 389
153 117 4
338 202 ...

output:

102

result:

ok 1 number(s): "102"

Test #24:

score: 0
Accepted
time: 14ms
memory: 3644kb

input:

800 1000
475 652 662
414 481 502
20 28 334
74 491 608
344 598 420
287 632 494
590 215 27
493 81 64
365 187 442
239 679 71
785 287 336
705 414 24
414 230 411
80 414 683
299 414 0
287 136 423
414 578 433
562 12 721
12 176 681
221 590 67
261 307 73
414 590 78
237 287 118
97 355 720
99 408 533
146 414 3...

output:

107

result:

ok 1 number(s): "107"

Test #25:

score: 0
Accepted
time: 234ms
memory: 3652kb

input:

800 1000
745 299 226
798 599 624
206 284 22
787 710 30
528 14 409
182 20 558
489 457 270
559 530 378
154 76 377
129 768 545
111 283 343
443 503 186
578 299 367
242 673 32
101 573 341
81 543 299
462 242 202
187 431 194
178 433 24
400 465 753
555 479 13
578 66 199
634 795 577
295 676 102
400 70 181
71...

output:

403

result:

ok 1 number(s): "403"

Test #26:

score: 0
Accepted
time: 244ms
memory: 3696kb

input:

800 1000
421 568 88
554 57 297
166 606 182
670 393 344
335 234 195
574 778 483
523 148 187
400 726 309
349 79 417
488 146 267
313 447 562
567 760 85
531 478 215
196 153 749
117 112 132
730 344 308
375 89 798
200 34 556
533 26 345
297 736 646
83 590 723
177 491 268
512 253 161
84 92 86
506 773 119
26...

output:

405

result:

ok 1 number(s): "405"

Test #27:

score: 0
Accepted
time: 278ms
memory: 3616kb

input:

800 1000
280 747 242
348 658 502
389 560 416
137 202 102
643 431 628
251 643 281
643 658 385
643 2 186
541 43 9
47 310 570
643 631 317
202 180 352
643 204 737
661 229 587
663 280 100
643 222 506
529 792 450
4 774 348
322 643 347
280 637 193
253 202 21
280 790 548
402 643 654
375 542 77
431 369 99
54...

output:

408

result:

ok 1 number(s): "408"

Test #28:

score: 0
Accepted
time: 1330ms
memory: 3720kb

input:

800 1000
140 450 637
180 165 220
235 623 132
641 43 398
531 249 540
521 506 129
739 303 206
208 448 32
121 661 663
726 654 458
73 396 656
154 131 440
443 477 214
280 506 56
171 439 531
440 187 658
358 120 724
709 174 353
588 217 579
497 532 417
536 105 204
400 360 305
32 283 629
565 645 130
271 88 3...

output:

799

result:

ok 1 number(s): "799"

Test #29:

score: 0
Accepted
time: 1731ms
memory: 3636kb

input:

900 1000
757 851 24
652 105 630
49 845 434
642 313 764
304 699 702
85 539 258
140 381 62
830 252 221
273 367 883
255 118 390
285 181 397
699 231 168
194 50 417
285 570 644
156 545 231
18 105 457
869 373 271
42 46 614
506 203 449
402 392 590
138 503 576
514 418 750
428 278 182
281 880 228
535 538 142...

output:

899

result:

ok 1 number(s): "899"

Test #30:

score: 0
Accepted
time: 2000ms
memory: 3740kb

input:

1000 1000
786 825 531
928 449 459
852 46 234
797 939 354
233 543 812
799 257 149
270 126 583
753 239 555
175 374 519
985 485 696
308 259 869
211 109 40
863 608 817
208 738 502
664 228 558
480 33 539
269 333 907
574 965 493
589 758 766
791 1000 983
27 422 718
207 416 340
657 424 225
764 345 453
798 9...

output:

999

result:

ok 1 number(s): "999"

Test #31:

score: 0
Accepted
time: 2ms
memory: 3648kb

input:

1 1000
1 1 0
1 1 1
1 1 1
1 1 1
1 1 0
1 1 0
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 0
1 1 1
1 1 1
1 1 0
1 1 0
1 1 1
1 1 1
1 1 0
1 1 1
1 1 1
1 1 0
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 0
1 1 1
1 1 0
1 1 1
1 1 1
1 1 0
1 1 0
1 1 1
1 1 0
1 1 0
1 1 0
1 1 0
1 1 1
1 1 0
1 1 0
1 1 1
1 1 0
1 1 1
1 1 0...

output:

0

result:

ok 1 number(s): "0"

Test #32:

score: 0
Accepted
time: 2ms
memory: 3684kb

input:

2 1000
2 2 0
1 2 2
2 2 1
2 2 0
1 2 0
1 1 1
1 2 1
1 1 2
2 1 0
1 2 1
1 2 2
1 2 0
1 2 0
1 1 2
1 2 0
2 2 0
1 1 1
2 1 0
1 1 0
1 1 2
2 2 1
1 2 2
2 1 2
2 2 2
2 1 2
2 1 2
2 1 2
2 1 0
2 2 2
1 1 1
2 1 1
2 2 0
1 1 1
2 1 0
1 1 1
1 2 2
2 2 0
2 2 0
1 1 0
2 2 0
2 2 0
1 1 2
1 2 1
1 2 1
2 1 1
1 2 0
1 2 2
1 1 0
1 2 0...

output:

1

result:

ok 1 number(s): "1"

Test #33:

score: 0
Accepted
time: 2ms
memory: 3740kb

input:

3 1000
2 3 3
2 1 0
2 3 0
3 2 0
2 3 1
2 3 0
2 1 0
1 3 2
3 3 1
2 3 0
1 3 0
3 3 2
1 1 1
3 2 1
1 3 3
1 2 0
2 1 2
2 2 1
3 2 2
2 3 3
3 2 1
3 2 2
1 1 2
2 1 1
3 1 0
3 3 2
3 3 1
3 2 0
1 1 1
2 3 0
3 3 0
1 2 1
2 1 1
2 3 0
2 3 2
2 2 2
2 3 1
2 1 3
2 2 1
2 3 1
1 2 0
1 1 1
1 3 1
3 2 1
3 2 3
3 2 1
3 3 3
1 1 0
2 3 3...

output:

2

result:

ok 1 number(s): "2"

Test #34:

score: 0
Accepted
time: 2ms
memory: 3576kb

input:

1 0

output:

0

result:

ok 1 number(s): "0"

Test #35:

score: -100
Dangerous Syscalls

input:

1000 999
424 501 424
397 773 536
990 95 481
37 170 825
440 924 663
640 444 280
744 463 313
483 25 915
573 752 38
945 670 812
515 298 473
284 984 609
168 274 177
108 730 750
351 566 98
836 631 356
928 831 226
497 867 488
947 463 849
788 421 348
717 658 102
986 322 927
32 662 667
639 285 939
93 651 97...

output:


result: