//1L1YA
#include<bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3,unrool-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
#define Pb push_back
#define F first
#define S second
#define endl '\n'
#define sep ' '
#define all(x) x.begin(),x.end()
#define al(x,n) x+1,x+n+1
#define SZ(x) ((int)x.size())
#define lc (id<<1)
#define rc (lc|1)
#define mid (l+r>>1)
#define dokme(x) cout << x << endl, exit(0)
#define sik(x) cout << x << endl;continue;
#define FastIO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define FileIO freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll oo=1e18;
const int mod=1e9+7;
const int inf=1e9+111;
const int N=1e6+11;
const int lg=23;
ll n,m,q,l[N],r[N],sz[N],ps1[N],ps2[N],par[N];
vector<pair<int,pii>> E;
vector<int> Q;
int getpar(int v){
return par[v]==v?v:par[v]=getpar(par[v]);
}
bool Union(int u,int v){
u=getpar(u);v=getpar(v);
if(u==v) return 0;
if(sz[u]>sz[v]) swap(u,v);
sz[v]+=sz[u];
par[u]=v;
return 1;
}
int main(){
FastIO
cin >> n >> m;
for(int i=1;i<=m;i++){
int u,v,w;
cin >> u >> v >> w;
E.Pb({w,{u,v}});
}
E.Pb({0,{0,0}});
sort(all(E));
cin >> q;
for(int i=1;i<=q;i++){
int x;cin >> x;
Q.Pb(x);
}
fill(r,r+m+1,m+1);
for(int i=1;i<=m;i++){
for(int j=1;j<=n;j++) par[j]=j,sz[j]=1;
int j=i-1;
while(j){
Union(E[j].S.F,E[j].S.S);
if(getpar(E[i].S.F)==getpar(E[i].S.S)) break;
j--;
}
l[i]=j;
r[j]=i;
}
for(int i=1;i<=m;i++){
int L=0;
if(l[i]) L=lower_bound(all(Q),(E[l[i]].F+E[i].F+1)/2)-Q.begin();
int k=lower_bound(all(Q),E[i].F)-Q.begin();
int R=q;
if(r[i]!=m+1) R=lower_bound(all(Q),(E[i].F+E[r[i]].F-1)/2+1)-Q.begin();
ps1[L]+=E[i].F;
ps1[k]-=E[i].F*2;
ps1[R]+=E[i].F;
ps2[L]--;
ps2[k]+=2;
ps2[R]--;
}
for(int i=0;i<q;i++){
cout << ps1[i]+ps2[i]*Q[i] << endl;
ps1[i+1]+=ps1[i];ps2[i+1]+=ps2[i];
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 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 |
1 ms |
600 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 |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 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 |
1 ms |
600 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 |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
543 ms |
4876 KB |
Output is correct |
21 |
Correct |
450 ms |
5060 KB |
Output is correct |
22 |
Correct |
481 ms |
4844 KB |
Output is correct |
23 |
Correct |
515 ms |
4920 KB |
Output is correct |
24 |
Correct |
519 ms |
4836 KB |
Output is correct |
25 |
Correct |
533 ms |
5060 KB |
Output is correct |
26 |
Correct |
513 ms |
4836 KB |
Output is correct |
27 |
Correct |
538 ms |
5076 KB |
Output is correct |
28 |
Correct |
525 ms |
5060 KB |
Output is correct |
29 |
Correct |
378 ms |
5064 KB |
Output is correct |
30 |
Correct |
532 ms |
4960 KB |
Output is correct |
31 |
Correct |
562 ms |
5144 KB |
Output is correct |
32 |
Correct |
579 ms |
5060 KB |
Output is correct |
33 |
Correct |
544 ms |
5060 KB |
Output is correct |
34 |
Correct |
241 ms |
5060 KB |
Output is correct |
35 |
Correct |
529 ms |
5060 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
621 ms |
40896 KB |
Output is correct |
5 |
Correct |
643 ms |
46216 KB |
Output is correct |
6 |
Correct |
630 ms |
46136 KB |
Output is correct |
7 |
Correct |
442 ms |
48004 KB |
Output is correct |
8 |
Correct |
371 ms |
48080 KB |
Output is correct |
9 |
Correct |
323 ms |
48192 KB |
Output is correct |
10 |
Correct |
603 ms |
46264 KB |
Output is correct |
11 |
Correct |
347 ms |
48308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 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 |
1 ms |
600 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 |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
139 ms |
41960 KB |
Output is correct |
21 |
Correct |
140 ms |
42180 KB |
Output is correct |
22 |
Correct |
140 ms |
42180 KB |
Output is correct |
23 |
Correct |
134 ms |
41980 KB |
Output is correct |
24 |
Correct |
134 ms |
42176 KB |
Output is correct |
25 |
Correct |
137 ms |
42144 KB |
Output is correct |
26 |
Correct |
146 ms |
42152 KB |
Output is correct |
27 |
Correct |
135 ms |
42160 KB |
Output is correct |
28 |
Correct |
136 ms |
41920 KB |
Output is correct |
29 |
Correct |
141 ms |
42152 KB |
Output is correct |
30 |
Correct |
136 ms |
42244 KB |
Output is correct |
31 |
Correct |
128 ms |
41920 KB |
Output is correct |
32 |
Correct |
132 ms |
42748 KB |
Output is correct |
33 |
Correct |
131 ms |
41928 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 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 |
1 ms |
600 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 |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
543 ms |
4876 KB |
Output is correct |
21 |
Correct |
450 ms |
5060 KB |
Output is correct |
22 |
Correct |
481 ms |
4844 KB |
Output is correct |
23 |
Correct |
515 ms |
4920 KB |
Output is correct |
24 |
Correct |
519 ms |
4836 KB |
Output is correct |
25 |
Correct |
533 ms |
5060 KB |
Output is correct |
26 |
Correct |
513 ms |
4836 KB |
Output is correct |
27 |
Correct |
538 ms |
5076 KB |
Output is correct |
28 |
Correct |
525 ms |
5060 KB |
Output is correct |
29 |
Correct |
378 ms |
5064 KB |
Output is correct |
30 |
Correct |
532 ms |
4960 KB |
Output is correct |
31 |
Correct |
562 ms |
5144 KB |
Output is correct |
32 |
Correct |
579 ms |
5060 KB |
Output is correct |
33 |
Correct |
544 ms |
5060 KB |
Output is correct |
34 |
Correct |
241 ms |
5060 KB |
Output is correct |
35 |
Correct |
529 ms |
5060 KB |
Output is correct |
36 |
Correct |
534 ms |
5780 KB |
Output is correct |
37 |
Correct |
439 ms |
5828 KB |
Output is correct |
38 |
Correct |
454 ms |
5644 KB |
Output is correct |
39 |
Correct |
502 ms |
5700 KB |
Output is correct |
40 |
Correct |
525 ms |
5900 KB |
Output is correct |
41 |
Correct |
501 ms |
5828 KB |
Output is correct |
42 |
Correct |
535 ms |
5624 KB |
Output is correct |
43 |
Correct |
526 ms |
5824 KB |
Output is correct |
44 |
Correct |
496 ms |
5836 KB |
Output is correct |
45 |
Correct |
387 ms |
6060 KB |
Output is correct |
46 |
Correct |
527 ms |
5868 KB |
Output is correct |
47 |
Correct |
538 ms |
5704 KB |
Output is correct |
48 |
Correct |
502 ms |
5720 KB |
Output is correct |
49 |
Correct |
536 ms |
5864 KB |
Output is correct |
50 |
Correct |
281 ms |
6000 KB |
Output is correct |
51 |
Correct |
529 ms |
5884 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 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 |
1 ms |
600 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 |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
543 ms |
4876 KB |
Output is correct |
21 |
Correct |
450 ms |
5060 KB |
Output is correct |
22 |
Correct |
481 ms |
4844 KB |
Output is correct |
23 |
Correct |
515 ms |
4920 KB |
Output is correct |
24 |
Correct |
519 ms |
4836 KB |
Output is correct |
25 |
Correct |
533 ms |
5060 KB |
Output is correct |
26 |
Correct |
513 ms |
4836 KB |
Output is correct |
27 |
Correct |
538 ms |
5076 KB |
Output is correct |
28 |
Correct |
525 ms |
5060 KB |
Output is correct |
29 |
Correct |
378 ms |
5064 KB |
Output is correct |
30 |
Correct |
532 ms |
4960 KB |
Output is correct |
31 |
Correct |
562 ms |
5144 KB |
Output is correct |
32 |
Correct |
579 ms |
5060 KB |
Output is correct |
33 |
Correct |
544 ms |
5060 KB |
Output is correct |
34 |
Correct |
241 ms |
5060 KB |
Output is correct |
35 |
Correct |
529 ms |
5060 KB |
Output is correct |
36 |
Correct |
0 ms |
344 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
621 ms |
40896 KB |
Output is correct |
40 |
Correct |
643 ms |
46216 KB |
Output is correct |
41 |
Correct |
630 ms |
46136 KB |
Output is correct |
42 |
Correct |
442 ms |
48004 KB |
Output is correct |
43 |
Correct |
371 ms |
48080 KB |
Output is correct |
44 |
Correct |
323 ms |
48192 KB |
Output is correct |
45 |
Correct |
603 ms |
46264 KB |
Output is correct |
46 |
Correct |
347 ms |
48308 KB |
Output is correct |
47 |
Correct |
1 ms |
344 KB |
Output is correct |
48 |
Correct |
139 ms |
41960 KB |
Output is correct |
49 |
Correct |
140 ms |
42180 KB |
Output is correct |
50 |
Correct |
140 ms |
42180 KB |
Output is correct |
51 |
Correct |
134 ms |
41980 KB |
Output is correct |
52 |
Correct |
134 ms |
42176 KB |
Output is correct |
53 |
Correct |
137 ms |
42144 KB |
Output is correct |
54 |
Correct |
146 ms |
42152 KB |
Output is correct |
55 |
Correct |
135 ms |
42160 KB |
Output is correct |
56 |
Correct |
136 ms |
41920 KB |
Output is correct |
57 |
Correct |
141 ms |
42152 KB |
Output is correct |
58 |
Correct |
136 ms |
42244 KB |
Output is correct |
59 |
Correct |
128 ms |
41920 KB |
Output is correct |
60 |
Correct |
132 ms |
42748 KB |
Output is correct |
61 |
Correct |
131 ms |
41928 KB |
Output is correct |
62 |
Correct |
534 ms |
5780 KB |
Output is correct |
63 |
Correct |
439 ms |
5828 KB |
Output is correct |
64 |
Correct |
454 ms |
5644 KB |
Output is correct |
65 |
Correct |
502 ms |
5700 KB |
Output is correct |
66 |
Correct |
525 ms |
5900 KB |
Output is correct |
67 |
Correct |
501 ms |
5828 KB |
Output is correct |
68 |
Correct |
535 ms |
5624 KB |
Output is correct |
69 |
Correct |
526 ms |
5824 KB |
Output is correct |
70 |
Correct |
496 ms |
5836 KB |
Output is correct |
71 |
Correct |
387 ms |
6060 KB |
Output is correct |
72 |
Correct |
527 ms |
5868 KB |
Output is correct |
73 |
Correct |
538 ms |
5704 KB |
Output is correct |
74 |
Correct |
502 ms |
5720 KB |
Output is correct |
75 |
Correct |
536 ms |
5864 KB |
Output is correct |
76 |
Correct |
281 ms |
6000 KB |
Output is correct |
77 |
Correct |
529 ms |
5884 KB |
Output is correct |
78 |
Correct |
653 ms |
45056 KB |
Output is correct |
79 |
Correct |
565 ms |
47176 KB |
Output is correct |
80 |
Correct |
616 ms |
46224 KB |
Output is correct |
81 |
Correct |
674 ms |
46008 KB |
Output is correct |
82 |
Correct |
688 ms |
45192 KB |
Output is correct |
83 |
Correct |
714 ms |
45136 KB |
Output is correct |
84 |
Correct |
688 ms |
45108 KB |
Output is correct |
85 |
Correct |
673 ms |
45040 KB |
Output is correct |
86 |
Correct |
669 ms |
45128 KB |
Output is correct |
87 |
Correct |
528 ms |
46632 KB |
Output is correct |
88 |
Correct |
684 ms |
45140 KB |
Output is correct |
89 |
Correct |
689 ms |
45096 KB |
Output is correct |
90 |
Correct |
644 ms |
45308 KB |
Output is correct |
91 |
Correct |
656 ms |
44988 KB |
Output is correct |
92 |
Correct |
365 ms |
47928 KB |
Output is correct |
93 |
Correct |
681 ms |
46600 KB |
Output is correct |