// Judges with GCC >= 12 only needs Ofast
// #pragma GCC optimize("O3,no-stack-protector,fast-math,unroll-loops,tree-vectorize")
// MLE optimization
// #pragma GCC optimize("conserve-stack")
// Old judges
// #pragma GCC target("sse4.2,popcnt,lzcnt,abm,mmx,fma,bmi,bmi2")
// New judges. Test with assert(__builtin_cpu_supports("avx2"));
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
// Atcoder
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma")
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
- insert(x)
- find_by_order(k): return iterator to the k-th smallest element
- order_of_key(x): the number of elements that are strictly smaller
*/
#include<bits/stdc++.h>
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_real_distribution<> pp(0.0,1.0);
//#define int long long
#define ld long double
#define pii pair<int,int>
#define piii pair<int,pii>
#define mpp make_pair
#define fi first
#define se second
const int inf=1e9;
const int mod=1e9+7;
const int maxn=200005;
const int bl=650;
const int maxs=655;
const int maxm=200005;
const int maxq=500005;
const int maxl=20;
const int maxa=250000;
const int root=3;
/*
int power(int a,int n){
int res=1;
while(n){
if(n&1) res=res*a%mod;
a=a*a%mod;n>>=1;
}
return res;
}
const int iroot=power(3,mod-2);
*/
const int base=101;
void solve(){
int n,m;cin >> n >> m;
vector<vector<pii>> edge(n+1);
vector<piii> e,f;
for(int i=1;i<=m;i++){
int u,v,w;cin >> u >> v >> w;
e.push_back({w,{u,v}});
}
sort(e.begin(),e.end());
function<piii(int,int,int)> dfs = [&](int u,int t,int p){
if(u==t) return mpp(inf,mpp(inf,inf));
for(auto &[v,w]:edge[u]){
if(v==p) continue;
piii d=dfs(v,t,u);
if(d.fi!=-1) return min(d,mpp(w,mpp(u,v)));
}
return mpp(-1,mpp(-1,-1));
};
auto del = [&](int u,int v,int w){
edge[u].erase(find(edge[u].begin(),edge[u].end(),mpp(v,w)));
edge[v].erase(find(edge[v].begin(),edge[v].end(),mpp(u,w)));
};
auto add = [&](int u,int v,int w){
edge[u].push_back({v,w});
edge[v].push_back({u,w});
};
for(auto x:e){
int u=x.se.fi,v=x.se.se,w=x.fi;
piii d=dfs(u,v,0);
if(d.fi==-1) f.push_back({0,{-1,w}});
else{
f.push_back({(d.fi+w+1)>>1,{-2,d.fi+w}});
del(d.se.fi,d.se.se,d.fi);
}
f.push_back({w,{2,-2*w}});
add(u,v,w);
}
sort(f.begin(),f.end());
long long c=0,k=0;
int q,cur=0;cin >> q;
while(q--){
int x;cin >> x;
while(cur<(int)f.size() && f[cur].fi<=x) c+=f[cur].se.fi,k+=f[cur++].se.se;
cout << x*c+k << '\n';
}
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
int test=1;//cin >> test;
while(test--) solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
324 KB |
Output is correct |
9 |
Correct |
0 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
320 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
324 KB |
Output is correct |
9 |
Correct |
0 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
320 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
328 KB |
Output is correct |
20 |
Correct |
410 ms |
6424 KB |
Output is correct |
21 |
Correct |
255 ms |
6464 KB |
Output is correct |
22 |
Correct |
346 ms |
6452 KB |
Output is correct |
23 |
Correct |
381 ms |
6468 KB |
Output is correct |
24 |
Correct |
336 ms |
6420 KB |
Output is correct |
25 |
Correct |
431 ms |
6448 KB |
Output is correct |
26 |
Correct |
399 ms |
6396 KB |
Output is correct |
27 |
Correct |
425 ms |
6452 KB |
Output is correct |
28 |
Correct |
434 ms |
6384 KB |
Output is correct |
29 |
Correct |
379 ms |
7824 KB |
Output is correct |
30 |
Correct |
411 ms |
6460 KB |
Output is correct |
31 |
Correct |
409 ms |
6484 KB |
Output is correct |
32 |
Correct |
411 ms |
6488 KB |
Output is correct |
33 |
Correct |
426 ms |
6412 KB |
Output is correct |
34 |
Correct |
349 ms |
7904 KB |
Output is correct |
35 |
Correct |
423 ms |
6552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
382 ms |
15008 KB |
Output is correct |
5 |
Correct |
385 ms |
15016 KB |
Output is correct |
6 |
Correct |
390 ms |
15080 KB |
Output is correct |
7 |
Correct |
221 ms |
17008 KB |
Output is correct |
8 |
Correct |
207 ms |
17124 KB |
Output is correct |
9 |
Correct |
208 ms |
17100 KB |
Output is correct |
10 |
Correct |
405 ms |
15188 KB |
Output is correct |
11 |
Correct |
199 ms |
17040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
324 KB |
Output is correct |
9 |
Correct |
0 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
320 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
154 ms |
22356 KB |
Output is correct |
21 |
Correct |
159 ms |
22476 KB |
Output is correct |
22 |
Correct |
165 ms |
22348 KB |
Output is correct |
23 |
Correct |
164 ms |
22360 KB |
Output is correct |
24 |
Correct |
152 ms |
22404 KB |
Output is correct |
25 |
Correct |
146 ms |
22348 KB |
Output is correct |
26 |
Correct |
163 ms |
22264 KB |
Output is correct |
27 |
Correct |
184 ms |
22380 KB |
Output is correct |
28 |
Correct |
145 ms |
22292 KB |
Output is correct |
29 |
Correct |
140 ms |
22352 KB |
Output is correct |
30 |
Correct |
161 ms |
22476 KB |
Output is correct |
31 |
Correct |
148 ms |
22152 KB |
Output is correct |
32 |
Correct |
196 ms |
23044 KB |
Output is correct |
33 |
Correct |
174 ms |
22148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
324 KB |
Output is correct |
9 |
Correct |
0 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
320 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
328 KB |
Output is correct |
20 |
Correct |
410 ms |
6424 KB |
Output is correct |
21 |
Correct |
255 ms |
6464 KB |
Output is correct |
22 |
Correct |
346 ms |
6452 KB |
Output is correct |
23 |
Correct |
381 ms |
6468 KB |
Output is correct |
24 |
Correct |
336 ms |
6420 KB |
Output is correct |
25 |
Correct |
431 ms |
6448 KB |
Output is correct |
26 |
Correct |
399 ms |
6396 KB |
Output is correct |
27 |
Correct |
425 ms |
6452 KB |
Output is correct |
28 |
Correct |
434 ms |
6384 KB |
Output is correct |
29 |
Correct |
379 ms |
7824 KB |
Output is correct |
30 |
Correct |
411 ms |
6460 KB |
Output is correct |
31 |
Correct |
409 ms |
6484 KB |
Output is correct |
32 |
Correct |
411 ms |
6488 KB |
Output is correct |
33 |
Correct |
426 ms |
6412 KB |
Output is correct |
34 |
Correct |
349 ms |
7904 KB |
Output is correct |
35 |
Correct |
423 ms |
6552 KB |
Output is correct |
36 |
Correct |
445 ms |
6648 KB |
Output is correct |
37 |
Correct |
235 ms |
6564 KB |
Output is correct |
38 |
Correct |
358 ms |
6656 KB |
Output is correct |
39 |
Correct |
388 ms |
6704 KB |
Output is correct |
40 |
Correct |
334 ms |
6672 KB |
Output is correct |
41 |
Correct |
398 ms |
6624 KB |
Output is correct |
42 |
Correct |
440 ms |
6628 KB |
Output is correct |
43 |
Correct |
414 ms |
6648 KB |
Output is correct |
44 |
Correct |
425 ms |
6564 KB |
Output is correct |
45 |
Correct |
371 ms |
7984 KB |
Output is correct |
46 |
Correct |
412 ms |
6672 KB |
Output is correct |
47 |
Correct |
411 ms |
6680 KB |
Output is correct |
48 |
Correct |
432 ms |
6608 KB |
Output is correct |
49 |
Correct |
408 ms |
6596 KB |
Output is correct |
50 |
Correct |
354 ms |
8244 KB |
Output is correct |
51 |
Correct |
427 ms |
6628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
324 KB |
Output is correct |
9 |
Correct |
0 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
320 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
328 KB |
Output is correct |
20 |
Correct |
410 ms |
6424 KB |
Output is correct |
21 |
Correct |
255 ms |
6464 KB |
Output is correct |
22 |
Correct |
346 ms |
6452 KB |
Output is correct |
23 |
Correct |
381 ms |
6468 KB |
Output is correct |
24 |
Correct |
336 ms |
6420 KB |
Output is correct |
25 |
Correct |
431 ms |
6448 KB |
Output is correct |
26 |
Correct |
399 ms |
6396 KB |
Output is correct |
27 |
Correct |
425 ms |
6452 KB |
Output is correct |
28 |
Correct |
434 ms |
6384 KB |
Output is correct |
29 |
Correct |
379 ms |
7824 KB |
Output is correct |
30 |
Correct |
411 ms |
6460 KB |
Output is correct |
31 |
Correct |
409 ms |
6484 KB |
Output is correct |
32 |
Correct |
411 ms |
6488 KB |
Output is correct |
33 |
Correct |
426 ms |
6412 KB |
Output is correct |
34 |
Correct |
349 ms |
7904 KB |
Output is correct |
35 |
Correct |
423 ms |
6552 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
382 ms |
15008 KB |
Output is correct |
40 |
Correct |
385 ms |
15016 KB |
Output is correct |
41 |
Correct |
390 ms |
15080 KB |
Output is correct |
42 |
Correct |
221 ms |
17008 KB |
Output is correct |
43 |
Correct |
207 ms |
17124 KB |
Output is correct |
44 |
Correct |
208 ms |
17100 KB |
Output is correct |
45 |
Correct |
405 ms |
15188 KB |
Output is correct |
46 |
Correct |
199 ms |
17040 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
154 ms |
22356 KB |
Output is correct |
49 |
Correct |
159 ms |
22476 KB |
Output is correct |
50 |
Correct |
165 ms |
22348 KB |
Output is correct |
51 |
Correct |
164 ms |
22360 KB |
Output is correct |
52 |
Correct |
152 ms |
22404 KB |
Output is correct |
53 |
Correct |
146 ms |
22348 KB |
Output is correct |
54 |
Correct |
163 ms |
22264 KB |
Output is correct |
55 |
Correct |
184 ms |
22380 KB |
Output is correct |
56 |
Correct |
145 ms |
22292 KB |
Output is correct |
57 |
Correct |
140 ms |
22352 KB |
Output is correct |
58 |
Correct |
161 ms |
22476 KB |
Output is correct |
59 |
Correct |
148 ms |
22152 KB |
Output is correct |
60 |
Correct |
196 ms |
23044 KB |
Output is correct |
61 |
Correct |
174 ms |
22148 KB |
Output is correct |
62 |
Correct |
445 ms |
6648 KB |
Output is correct |
63 |
Correct |
235 ms |
6564 KB |
Output is correct |
64 |
Correct |
358 ms |
6656 KB |
Output is correct |
65 |
Correct |
388 ms |
6704 KB |
Output is correct |
66 |
Correct |
334 ms |
6672 KB |
Output is correct |
67 |
Correct |
398 ms |
6624 KB |
Output is correct |
68 |
Correct |
440 ms |
6628 KB |
Output is correct |
69 |
Correct |
414 ms |
6648 KB |
Output is correct |
70 |
Correct |
425 ms |
6564 KB |
Output is correct |
71 |
Correct |
371 ms |
7984 KB |
Output is correct |
72 |
Correct |
412 ms |
6672 KB |
Output is correct |
73 |
Correct |
411 ms |
6680 KB |
Output is correct |
74 |
Correct |
432 ms |
6608 KB |
Output is correct |
75 |
Correct |
408 ms |
6596 KB |
Output is correct |
76 |
Correct |
354 ms |
8244 KB |
Output is correct |
77 |
Correct |
427 ms |
6628 KB |
Output is correct |
78 |
Correct |
585 ms |
25416 KB |
Output is correct |
79 |
Correct |
363 ms |
27548 KB |
Output is correct |
80 |
Correct |
513 ms |
26496 KB |
Output is correct |
81 |
Correct |
506 ms |
26564 KB |
Output is correct |
82 |
Correct |
497 ms |
25556 KB |
Output is correct |
83 |
Correct |
554 ms |
25456 KB |
Output is correct |
84 |
Correct |
550 ms |
25496 KB |
Output is correct |
85 |
Correct |
564 ms |
25448 KB |
Output is correct |
86 |
Correct |
585 ms |
25544 KB |
Output is correct |
87 |
Correct |
511 ms |
28516 KB |
Output is correct |
88 |
Correct |
559 ms |
25448 KB |
Output is correct |
89 |
Correct |
612 ms |
25452 KB |
Output is correct |
90 |
Correct |
569 ms |
25576 KB |
Output is correct |
91 |
Correct |
543 ms |
25352 KB |
Output is correct |
92 |
Correct |
502 ms |
29812 KB |
Output is correct |
93 |
Correct |
545 ms |
26552 KB |
Output is correct |