#include<bits/stdc++.h>
using namespace std;
using ll = long long;
struct dsu{
vector<ll> p;
dsu(ll N):p(N,-1){}
ll g(ll x){return p[x]==-1?x:p[x]=g(p[x]);}
bool m(ll a, ll b){
a=g(a);b=g(b);
if(a!=b)p[a]=b;
return a!=b;
}
};
struct edge{
ll u,v,w;
bool operator<(const edge& o) const{
return w<o.w;
}
};
int main(){
ios::sync_with_stdio(0);cin.tie(0);
ll n,m;
cin >> n >> m;
vector<edge> a(m);
for(edge &o : a) cin >> o.u >> o.v >> o.w, o.u--,o.v--;
ll q;
cin >> q;
while(q--){
ll x;
cin >> x;
vector<edge> b = a;
for(edge &o : b) o.w = abs(x-o.w);
sort(b.begin(),b.end());
ll ans = 0;
dsu d(n);
for(auto [u,v,w] : b){
ans += w*d.m(u,v);
}
cout << ans << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
456 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
456 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 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 |
452 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
456 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
456 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 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 |
452 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
86 ms |
6868 KB |
Output is correct |
21 |
Correct |
88 ms |
6764 KB |
Output is correct |
22 |
Correct |
87 ms |
6820 KB |
Output is correct |
23 |
Correct |
87 ms |
6744 KB |
Output is correct |
24 |
Correct |
87 ms |
6740 KB |
Output is correct |
25 |
Correct |
86 ms |
6748 KB |
Output is correct |
26 |
Correct |
85 ms |
6744 KB |
Output is correct |
27 |
Correct |
86 ms |
6748 KB |
Output is correct |
28 |
Correct |
71 ms |
6944 KB |
Output is correct |
29 |
Correct |
48 ms |
6740 KB |
Output is correct |
30 |
Correct |
84 ms |
6744 KB |
Output is correct |
31 |
Correct |
86 ms |
6740 KB |
Output is correct |
32 |
Correct |
90 ms |
6956 KB |
Output is correct |
33 |
Correct |
85 ms |
6740 KB |
Output is correct |
34 |
Correct |
37 ms |
6964 KB |
Output is correct |
35 |
Correct |
85 ms |
6756 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
424 KB |
Output is correct |
3 |
Correct |
0 ms |
600 KB |
Output is correct |
4 |
Execution timed out |
5067 ms |
7208 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
456 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
456 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 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 |
452 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Execution timed out |
5079 ms |
5440 KB |
Time limit exceeded |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
456 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
456 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 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 |
452 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
86 ms |
6868 KB |
Output is correct |
21 |
Correct |
88 ms |
6764 KB |
Output is correct |
22 |
Correct |
87 ms |
6820 KB |
Output is correct |
23 |
Correct |
87 ms |
6744 KB |
Output is correct |
24 |
Correct |
87 ms |
6740 KB |
Output is correct |
25 |
Correct |
86 ms |
6748 KB |
Output is correct |
26 |
Correct |
85 ms |
6744 KB |
Output is correct |
27 |
Correct |
86 ms |
6748 KB |
Output is correct |
28 |
Correct |
71 ms |
6944 KB |
Output is correct |
29 |
Correct |
48 ms |
6740 KB |
Output is correct |
30 |
Correct |
84 ms |
6744 KB |
Output is correct |
31 |
Correct |
86 ms |
6740 KB |
Output is correct |
32 |
Correct |
90 ms |
6956 KB |
Output is correct |
33 |
Correct |
85 ms |
6740 KB |
Output is correct |
34 |
Correct |
37 ms |
6964 KB |
Output is correct |
35 |
Correct |
85 ms |
6756 KB |
Output is correct |
36 |
Execution timed out |
5018 ms |
7216 KB |
Time limit exceeded |
37 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
456 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
456 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 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 |
452 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
86 ms |
6868 KB |
Output is correct |
21 |
Correct |
88 ms |
6764 KB |
Output is correct |
22 |
Correct |
87 ms |
6820 KB |
Output is correct |
23 |
Correct |
87 ms |
6744 KB |
Output is correct |
24 |
Correct |
87 ms |
6740 KB |
Output is correct |
25 |
Correct |
86 ms |
6748 KB |
Output is correct |
26 |
Correct |
85 ms |
6744 KB |
Output is correct |
27 |
Correct |
86 ms |
6748 KB |
Output is correct |
28 |
Correct |
71 ms |
6944 KB |
Output is correct |
29 |
Correct |
48 ms |
6740 KB |
Output is correct |
30 |
Correct |
84 ms |
6744 KB |
Output is correct |
31 |
Correct |
86 ms |
6740 KB |
Output is correct |
32 |
Correct |
90 ms |
6956 KB |
Output is correct |
33 |
Correct |
85 ms |
6740 KB |
Output is correct |
34 |
Correct |
37 ms |
6964 KB |
Output is correct |
35 |
Correct |
85 ms |
6756 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
424 KB |
Output is correct |
38 |
Correct |
0 ms |
600 KB |
Output is correct |
39 |
Execution timed out |
5067 ms |
7208 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |