Submission #1077614

# Submission time Handle Problem Language Result Execution time Memory
1077614 2024-08-27T08:21:33 Z vjudge1 Reconstruction Project (JOI22_reconstruction) C++17
7 / 100
5000 ms 4944 KB
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define ppb pop_back
#define ep insert
#define endl '\n'
#define elif else if
#define pow pwr
#define sqrt sqrtt
#define int long long
#define ll long long
typedef unsigned long long ull;
using namespace std;
struct edge{
	int a,b,w;
};
const int N=505,M=1e5+5;
int n,sz[N],par[N],m,q,W;
edge e[M];
bool cmp(edge x,edge y){
	return abs(x.w-W)<abs(y.w-W);
}
int getpar(int x){
	if (x==par[x]) return x;
	return par[x]=getpar(par[x]);
}
int link(int x,int y){
	x=getpar(x);
	y=getpar(y);
	if (x==y) return 0;
	if (sz[x]>sz[y]) swap(x,y);
	sz[y]+=sz[x];
	par[x]=y;
	return 1;
}
int32_t main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	cin>>n>>m;
	for (int i=1;i<=m;i++) cin>>e[i].a>>e[i].b>>e[i].w;
	cin>>q;
	while (q--){
		cin>>W;
		sort(e+1,e+1+m,cmp);
		for (int i=1;i<=n;i++) par[i]=i,sz[i]=1;
		int ans=0;
		for (int i=1;i<=m;i++) ans+=link(e[i].a,e[i].b)*abs(e[i].w-W);
		cout<<ans<<endl;
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 126 ms 4460 KB Output is correct
21 Correct 123 ms 4504 KB Output is correct
22 Correct 126 ms 4376 KB Output is correct
23 Correct 123 ms 4500 KB Output is correct
24 Correct 122 ms 4500 KB Output is correct
25 Correct 127 ms 4492 KB Output is correct
26 Correct 120 ms 4444 KB Output is correct
27 Correct 125 ms 4500 KB Output is correct
28 Correct 95 ms 4292 KB Output is correct
29 Correct 80 ms 4440 KB Output is correct
30 Correct 125 ms 4444 KB Output is correct
31 Correct 119 ms 4508 KB Output is correct
32 Correct 118 ms 4444 KB Output is correct
33 Correct 127 ms 4500 KB Output is correct
34 Correct 81 ms 4592 KB Output is correct
35 Correct 100 ms 4384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Execution timed out 5020 ms 4680 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Execution timed out 5055 ms 3144 KB Time limit exceeded
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 126 ms 4460 KB Output is correct
21 Correct 123 ms 4504 KB Output is correct
22 Correct 126 ms 4376 KB Output is correct
23 Correct 123 ms 4500 KB Output is correct
24 Correct 122 ms 4500 KB Output is correct
25 Correct 127 ms 4492 KB Output is correct
26 Correct 120 ms 4444 KB Output is correct
27 Correct 125 ms 4500 KB Output is correct
28 Correct 95 ms 4292 KB Output is correct
29 Correct 80 ms 4440 KB Output is correct
30 Correct 125 ms 4444 KB Output is correct
31 Correct 119 ms 4508 KB Output is correct
32 Correct 118 ms 4444 KB Output is correct
33 Correct 127 ms 4500 KB Output is correct
34 Correct 81 ms 4592 KB Output is correct
35 Correct 100 ms 4384 KB Output is correct
36 Execution timed out 5098 ms 4944 KB Time limit exceeded
37 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 126 ms 4460 KB Output is correct
21 Correct 123 ms 4504 KB Output is correct
22 Correct 126 ms 4376 KB Output is correct
23 Correct 123 ms 4500 KB Output is correct
24 Correct 122 ms 4500 KB Output is correct
25 Correct 127 ms 4492 KB Output is correct
26 Correct 120 ms 4444 KB Output is correct
27 Correct 125 ms 4500 KB Output is correct
28 Correct 95 ms 4292 KB Output is correct
29 Correct 80 ms 4440 KB Output is correct
30 Correct 125 ms 4444 KB Output is correct
31 Correct 119 ms 4508 KB Output is correct
32 Correct 118 ms 4444 KB Output is correct
33 Correct 127 ms 4500 KB Output is correct
34 Correct 81 ms 4592 KB Output is correct
35 Correct 100 ms 4384 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Execution timed out 5020 ms 4680 KB Time limit exceeded
40 Halted 0 ms 0 KB -