QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#407546#7415. Fast Spanning TreeNetwork_ErrorWA 5ms22104kbC++141.4kb2024-05-08 23:12:172024-05-08 23:12:18

Judging History

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

  • [2024-05-08 23:12:18]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:22104kb
  • [2024-05-08 23:12:17]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define piii tuple<int,int,int>
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define deb(var) cerr<<#var<<'='<<(var)<<"; "
#define int long long
int n,m,a[300010],fa[300010],tag[300010];
priority_queue<pii,vector<pii>,greater<pii> > q[300010];
int u[300010],v[300010],w[300010],del[300010];

vector<int> ans;
int find(int i){return fa[i]==i?i:fa[i]=find(fa[i]);}
void upd(int i);
void chk(int u){
	while(q[u].size()&&a[u]>=q[u].top().fi+tag[u]){
		int x=q[u].top().se;
		q[u].pop();upd(x); u=find(u);
	}
}
void warn(int i){
	del[i]=1;
	int x=find(u[i]),y=find(v[i]);
	if(x==y)return;
	ans.pb(i);
	if(q[x].size()<q[y].size())swap(x,y);
//	tag[y]+=a[x],tag[x]+=a[y];
	while(q[y].size())
		q[x].push({q[y].top().fi+tag[y]-tag[x],q[y].top().se}),q[y].pop();
	fa[y]=x,a[x]+=a[y]; chk(x);
}
void upd(int i){
	if(del[i])return;
	int x=find(u[i]),y=find(v[i]);
	if(x==y)return;
	int T=w[i]-a[x]-a[y];
	if(T<=0)warn(i);
	else q[x].push({a[x]+(T+1)/2-tag[x],i}),
		 q[y].push({a[y]+(T+1)/2-tag[y],i});
}
void work(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)cin>>a[i];
	iota(fa+1,fa+n+1,1);
	for(int i=1;i<=m;i++)
		cin>>u[i]>>v[i]>>w[i],upd(i);
	cout<<ans.size()<<'\n';
	for(auto i:ans)cout<<i<<' ';
}
signed main(){
	ios::sync_with_stdio(0),
	cin.tie(0),cout.tie(0);
	int T=1;while(T--)work();return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 5ms
memory: 22024kb

input:

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

output:

4
2 3 1 4 

result:

ok 5 number(s): "4 2 3 1 4"

Test #2:

score: 0
Accepted
time: 4ms
memory: 20064kb

input:

3 5
3 2 2
1 2 6
1 2 6
1 2 3
1 2 6
2 3 6

output:

2
3 5 

result:

ok 3 number(s): "2 3 5"

Test #3:

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

input:

10 20
4 6 6 1 7 9 1 8 7 9
5 3 2
1 10 10
5 6 7
9 6 9
3 1 1
6 8 1
5 7 0
9 5 4
10 3 4
8 6 8
3 10 6
5 3 8
3 7 9
1 9 10
10 1 0
5 7 6
6 10 1
6 5 9
5 8 2
9 2 4

output:

8
1 2 3 4 5 6 7 20 

result:

ok 9 numbers

Test #4:

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

input:

10 20
0 10 4 6 2 0 2 0 2 8
5 10 8
7 1 6
10 5 0
9 8 0
5 8 4
5 1 8
10 3 6
5 4 3
9 2 6
10 3 6
4 3 1
3 10 3
6 1 3
3 2 5
6 9 2
4 2 5
10 6 5
8 6 3
2 1 0
2 3 6

output:

9
1 4 5 6 2 7 8 9 13 

result:

ok 10 numbers

Test #5:

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

input:

100 200
49 21 70 93 66 51 36 59 56 62 10 4 46 73 22 48 89 17 72 60 29 64 19 56 32 54 55 0 77 86 34 35 56 17 55 2 98 80 73 71 64 37 61 22 89 96 99 28 0 35 56 45 74 81 30 3 66 96 28 16 29 43 60 61 60 95 83 5 73 1 28 47 73 44 8 4 91 34 100 23 4 93 44 87 72 5 13 88 100 52 56 61 100 80 14 30 59 97 51 43
...

output:

96
1 2 4 5 6 7 8 10 11 12 13 14 15 16 17 18 19 9 20 21 22 23 25 26 3 27 28 29 30 31 32 33 35 36 37 38 39 40 41 42 44 45 46 47 48 49 50 51 52 53 34 54 55 56 58 59 60 61 62 63 64 66 67 68 69 70 71 72 74 76 78 80 81 82 87 89 91 94 95 96 100 43 101 24 84 107 109 110 117 119 129 142 144 169 170 195 

result:

ok 97 numbers

Test #6:

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

input:

100 200
24 84 94 70 81 51 70 9 39 61 34 89 37 23 21 52 19 65 37 53 85 70 27 74 46 45 49 76 36 51 38 8 91 84 30 21 82 93 54 4 65 44 66 78 42 42 74 11 12 66 24 88 65 75 78 55 61 45 21 83 29 24 85 37 73 25 25 40 96 100 26 28 18 30 56 41 15 11 88 61 42 74 8 97 14 34 5 39 24 94 84 8 3 54 75 62 73 36 58 4...

output:

98
1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 11 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 63 64 65 66 67 68 70 71 72 73 74 75 77 78 80 81 82 84 85 87 88 89 90 91 92 94 96 98 99 103 104 129 156 163 164 167 185 199 

result:

ok 99 numbers

Test #7:

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

input:

1000 2000
919 776 189 249 535 136 885 695 607 561 235 179 233 501 828 472 532 337 721 344 71 885 630 612 867 132 392 624 477 527 529 17 960 726 235 661 407 923 214 882 554 194 68 561 993 393 548 92 269 41 754 647 1 924 510 573 464 911 845 303 624 583 255 861 668 998 648 901 251 766 349 248 504 117 6...

output:

979
2 3 4 5 6 7 8 10 13 14 15 16 17 18 19 20 21 22 24 25 26 27 28 29 30 31 32 33 34 35 36 38 39 42 43 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 71 72 73 74 75 76 77 78 79 80 81 82 45 83 84 85 86 87 88 89 90 91 92 93 94 95 97 98 99 100 101 102 103 105 41 106 107 108 1...

result:

ok 980 numbers

Test #8:

score: -100
Wrong Answer
time: 0ms
memory: 16008kb

input:

1000 2000
838 14 274 368 930 991 554 645 860 709 557 447 647 723 384 339 801 423 843 957 649 71 997 106 521 713 275 876 396 541 377 586 934 998 330 221 529 635 515 216 643 742 507 270 902 288 440 622 950 258 295 505 358 540 452 414 888 601 815 386 759 689 742 840 994 786 974 648 379 102 450 754 624 ...

output:

970
1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 2 23 24 25 26 28 29 30 31 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 53 27 54 56 52 57 58 59 60 61 62 63 64 65 67 68 69 70 71 72 73 76 77 78 79 80 81 82 83 84 85 86 87 89 90 91 93 95 97 98 99 100 101 102 104 105 106 108 75 109 ...

result:

wrong answer 302nd numbers differ - expected: '66', found: '207'