#include<bits/stdc++.h>
#define pb push_back
#define pli pair<int,int>
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=long long;
const ll maxn=2e5;
const ll inf=1e18;
const ll mod=1e9+7;
ll n,m;
struct edge
{
ll w,u,v;
bool operator<(const edge&o)
{
return w<o.w;
}
}e[maxn];
vector<edge>vec;
ll lab[maxn];
ll findset(ll x)
{
return lab[x]<0?x:lab[x]=findset(lab[x]);
}
void unite(ll u,ll v)
{
u=findset(u);
v=findset(v);
if(u==v) return;
if(lab[u]>lab[v]) swap(u,v);
lab[u]+=lab[v];
lab[v]=u;
}
void solve()
{
cin >> n >> m;
for(int i=1;i<=m;i++)
{
cin >> e[i].u >> e[i].v >> e[i].w;
}
e[0].w=-inf;
e[m+1].w=inf;
sort(e+1,e+m+1);
for(int i=1;i<=m;i++)
{
ll l=0,r=m+1;
for(int j=1;j<=n;j++) lab[j]=-1;
for(int j=i+1;j<=m;j++)
{
unite(e[j].u,e[j].v);
if(findset(e[i].u)==findset(e[i].v))
{
r=j;
break;
}
}
for(int j=1;j<=n;j++) lab[j]=-1;
for(int j=i-1;j>=1;j--)
{
unite(e[j].u,e[j].v);
if(findset(e[i].u)==findset(e[i].v))
{
l=j;
break;
}
}
ll mid=(e[i].w+e[l].w)/2+1;
vec.pb({mid,-1,e[i].w});
vec.pb({e[i].w,2,-2*e[i].w});
mid=(e[i].w+e[r].w)/2;
vec.pb({mid+1,-1,e[i].w});
}
sort(vec.begin(),vec.end());
ll j=0;
ll q;
cin >> q;
ll cnt=0,sum=0;
while(q--)
{
ll x;
cin >> x;
while(j<vec.size()&&vec[j].w<=x)
{
cnt+=vec[j].u;
sum+=vec[j].v;
j++;
}
cout << cnt*x+sum<<'\n';
}
}
int main()
{
fastio
//freopen(TASKNAME".INP","r",stdin);
//freopen(TASKNAME".OUT","w",stdout);
solve();
}
Compilation message
reconstruction.cpp: In function 'void solve()':
reconstruction.cpp:85:16: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
85 | while(j<vec.size()&&vec[j].w<=x)
| ~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2516 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2404 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2524 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2652 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2516 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2404 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2524 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2652 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1182 ms |
19156 KB |
Output is correct |
21 |
Correct |
825 ms |
19892 KB |
Output is correct |
22 |
Correct |
900 ms |
19336 KB |
Output is correct |
23 |
Correct |
1004 ms |
20348 KB |
Output is correct |
24 |
Correct |
1166 ms |
19020 KB |
Output is correct |
25 |
Correct |
1127 ms |
20548 KB |
Output is correct |
26 |
Correct |
1198 ms |
20660 KB |
Output is correct |
27 |
Correct |
1188 ms |
19044 KB |
Output is correct |
28 |
Correct |
1178 ms |
19652 KB |
Output is correct |
29 |
Correct |
1162 ms |
19180 KB |
Output is correct |
30 |
Correct |
1191 ms |
19528 KB |
Output is correct |
31 |
Correct |
1191 ms |
19944 KB |
Output is correct |
32 |
Correct |
1218 ms |
20232 KB |
Output is correct |
33 |
Correct |
1223 ms |
19628 KB |
Output is correct |
34 |
Correct |
1182 ms |
20128 KB |
Output is correct |
35 |
Correct |
1179 ms |
18684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1167 ms |
36000 KB |
Output is correct |
5 |
Correct |
1153 ms |
34728 KB |
Output is correct |
6 |
Correct |
1204 ms |
35840 KB |
Output is correct |
7 |
Correct |
619 ms |
35972 KB |
Output is correct |
8 |
Correct |
463 ms |
37124 KB |
Output is correct |
9 |
Correct |
424 ms |
37428 KB |
Output is correct |
10 |
Correct |
1160 ms |
34496 KB |
Output is correct |
11 |
Correct |
429 ms |
36836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2516 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2404 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2524 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2652 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2392 KB |
Output is correct |
20 |
Correct |
154 ms |
24384 KB |
Output is correct |
21 |
Correct |
150 ms |
24608 KB |
Output is correct |
22 |
Correct |
151 ms |
24660 KB |
Output is correct |
23 |
Correct |
165 ms |
24592 KB |
Output is correct |
24 |
Correct |
151 ms |
24404 KB |
Output is correct |
25 |
Correct |
174 ms |
24816 KB |
Output is correct |
26 |
Correct |
156 ms |
24620 KB |
Output is correct |
27 |
Correct |
160 ms |
24616 KB |
Output is correct |
28 |
Correct |
155 ms |
24404 KB |
Output is correct |
29 |
Correct |
151 ms |
24404 KB |
Output is correct |
30 |
Correct |
154 ms |
24656 KB |
Output is correct |
31 |
Correct |
150 ms |
24304 KB |
Output is correct |
32 |
Correct |
151 ms |
25172 KB |
Output is correct |
33 |
Correct |
150 ms |
24404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2516 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2404 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2524 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2652 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1182 ms |
19156 KB |
Output is correct |
21 |
Correct |
825 ms |
19892 KB |
Output is correct |
22 |
Correct |
900 ms |
19336 KB |
Output is correct |
23 |
Correct |
1004 ms |
20348 KB |
Output is correct |
24 |
Correct |
1166 ms |
19020 KB |
Output is correct |
25 |
Correct |
1127 ms |
20548 KB |
Output is correct |
26 |
Correct |
1198 ms |
20660 KB |
Output is correct |
27 |
Correct |
1188 ms |
19044 KB |
Output is correct |
28 |
Correct |
1178 ms |
19652 KB |
Output is correct |
29 |
Correct |
1162 ms |
19180 KB |
Output is correct |
30 |
Correct |
1191 ms |
19528 KB |
Output is correct |
31 |
Correct |
1191 ms |
19944 KB |
Output is correct |
32 |
Correct |
1218 ms |
20232 KB |
Output is correct |
33 |
Correct |
1223 ms |
19628 KB |
Output is correct |
34 |
Correct |
1182 ms |
20128 KB |
Output is correct |
35 |
Correct |
1179 ms |
18684 KB |
Output is correct |
36 |
Correct |
1169 ms |
19668 KB |
Output is correct |
37 |
Correct |
842 ms |
19640 KB |
Output is correct |
38 |
Correct |
894 ms |
19272 KB |
Output is correct |
39 |
Correct |
997 ms |
20920 KB |
Output is correct |
40 |
Correct |
1145 ms |
19868 KB |
Output is correct |
41 |
Correct |
1143 ms |
19324 KB |
Output is correct |
42 |
Correct |
1160 ms |
20012 KB |
Output is correct |
43 |
Correct |
1158 ms |
19184 KB |
Output is correct |
44 |
Correct |
1163 ms |
19484 KB |
Output is correct |
45 |
Correct |
1160 ms |
20504 KB |
Output is correct |
46 |
Correct |
1202 ms |
19104 KB |
Output is correct |
47 |
Correct |
1165 ms |
19756 KB |
Output is correct |
48 |
Correct |
1166 ms |
20440 KB |
Output is correct |
49 |
Correct |
1162 ms |
20016 KB |
Output is correct |
50 |
Correct |
1146 ms |
19784 KB |
Output is correct |
51 |
Correct |
1164 ms |
20820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2516 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2404 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2524 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2652 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1182 ms |
19156 KB |
Output is correct |
21 |
Correct |
825 ms |
19892 KB |
Output is correct |
22 |
Correct |
900 ms |
19336 KB |
Output is correct |
23 |
Correct |
1004 ms |
20348 KB |
Output is correct |
24 |
Correct |
1166 ms |
19020 KB |
Output is correct |
25 |
Correct |
1127 ms |
20548 KB |
Output is correct |
26 |
Correct |
1198 ms |
20660 KB |
Output is correct |
27 |
Correct |
1188 ms |
19044 KB |
Output is correct |
28 |
Correct |
1178 ms |
19652 KB |
Output is correct |
29 |
Correct |
1162 ms |
19180 KB |
Output is correct |
30 |
Correct |
1191 ms |
19528 KB |
Output is correct |
31 |
Correct |
1191 ms |
19944 KB |
Output is correct |
32 |
Correct |
1218 ms |
20232 KB |
Output is correct |
33 |
Correct |
1223 ms |
19628 KB |
Output is correct |
34 |
Correct |
1182 ms |
20128 KB |
Output is correct |
35 |
Correct |
1179 ms |
18684 KB |
Output is correct |
36 |
Correct |
1 ms |
2396 KB |
Output is correct |
37 |
Correct |
1 ms |
2396 KB |
Output is correct |
38 |
Correct |
1 ms |
2396 KB |
Output is correct |
39 |
Correct |
1167 ms |
36000 KB |
Output is correct |
40 |
Correct |
1153 ms |
34728 KB |
Output is correct |
41 |
Correct |
1204 ms |
35840 KB |
Output is correct |
42 |
Correct |
619 ms |
35972 KB |
Output is correct |
43 |
Correct |
463 ms |
37124 KB |
Output is correct |
44 |
Correct |
424 ms |
37428 KB |
Output is correct |
45 |
Correct |
1160 ms |
34496 KB |
Output is correct |
46 |
Correct |
429 ms |
36836 KB |
Output is correct |
47 |
Correct |
1 ms |
2392 KB |
Output is correct |
48 |
Correct |
154 ms |
24384 KB |
Output is correct |
49 |
Correct |
150 ms |
24608 KB |
Output is correct |
50 |
Correct |
151 ms |
24660 KB |
Output is correct |
51 |
Correct |
165 ms |
24592 KB |
Output is correct |
52 |
Correct |
151 ms |
24404 KB |
Output is correct |
53 |
Correct |
174 ms |
24816 KB |
Output is correct |
54 |
Correct |
156 ms |
24620 KB |
Output is correct |
55 |
Correct |
160 ms |
24616 KB |
Output is correct |
56 |
Correct |
155 ms |
24404 KB |
Output is correct |
57 |
Correct |
151 ms |
24404 KB |
Output is correct |
58 |
Correct |
154 ms |
24656 KB |
Output is correct |
59 |
Correct |
150 ms |
24304 KB |
Output is correct |
60 |
Correct |
151 ms |
25172 KB |
Output is correct |
61 |
Correct |
150 ms |
24404 KB |
Output is correct |
62 |
Correct |
1169 ms |
19668 KB |
Output is correct |
63 |
Correct |
842 ms |
19640 KB |
Output is correct |
64 |
Correct |
894 ms |
19272 KB |
Output is correct |
65 |
Correct |
997 ms |
20920 KB |
Output is correct |
66 |
Correct |
1145 ms |
19868 KB |
Output is correct |
67 |
Correct |
1143 ms |
19324 KB |
Output is correct |
68 |
Correct |
1160 ms |
20012 KB |
Output is correct |
69 |
Correct |
1158 ms |
19184 KB |
Output is correct |
70 |
Correct |
1163 ms |
19484 KB |
Output is correct |
71 |
Correct |
1160 ms |
20504 KB |
Output is correct |
72 |
Correct |
1202 ms |
19104 KB |
Output is correct |
73 |
Correct |
1165 ms |
19756 KB |
Output is correct |
74 |
Correct |
1166 ms |
20440 KB |
Output is correct |
75 |
Correct |
1162 ms |
20016 KB |
Output is correct |
76 |
Correct |
1146 ms |
19784 KB |
Output is correct |
77 |
Correct |
1164 ms |
20820 KB |
Output is correct |
78 |
Correct |
1311 ms |
34220 KB |
Output is correct |
79 |
Correct |
974 ms |
35044 KB |
Output is correct |
80 |
Correct |
1049 ms |
35356 KB |
Output is correct |
81 |
Correct |
1148 ms |
35996 KB |
Output is correct |
82 |
Correct |
1290 ms |
34000 KB |
Output is correct |
83 |
Correct |
1266 ms |
33664 KB |
Output is correct |
84 |
Correct |
1307 ms |
33588 KB |
Output is correct |
85 |
Correct |
1325 ms |
34768 KB |
Output is correct |
86 |
Correct |
1292 ms |
34784 KB |
Output is correct |
87 |
Correct |
1302 ms |
35356 KB |
Output is correct |
88 |
Correct |
1334 ms |
34056 KB |
Output is correct |
89 |
Correct |
1311 ms |
34692 KB |
Output is correct |
90 |
Correct |
1315 ms |
33884 KB |
Output is correct |
91 |
Correct |
1329 ms |
35240 KB |
Output is correct |
92 |
Correct |
1299 ms |
37556 KB |
Output is correct |
93 |
Correct |
1324 ms |
35692 KB |
Output is correct |