/
3453.test.cpp
60 lines (46 loc) · 1.05 KB
/
3453.test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// verification-helper: PROBLEM https://yukicoder.me/problems/3453
#include <bits/stdc++.h>
using namespace std;
#define call_from_test
#include "../../toptree/toptree.cpp"
#include "../../toptree/steiner.cpp"
#undef call_from_test
signed main(){
cin.tie(0);
ios::sync_with_stdio(0);
const char newl = '\n';
const size_t N = 1e5;
using Cluster = SteinerTree<long long>;
TopTree<Vertex, Cluster, N> G;
int n;
cin>>n;
vector<Vertex*> vs(n);
for(int i=0;i<n;i++) vs[i]=G.create();
for(int i=1;i<n;i++){
int u,v,w;
cin>>u>>v>>w;
G.link(vs[u],Cluster(w),vs[v]);
}
int q;
cin>>q;
for(int i=0;i<q;i++){
int t;
cin>>t;
if(t==1){
int u,v,w,x;
cin>>u>>v>>w>>x;
G.cut(vs[u],vs[v]);
G.link(vs[v],Cluster(x),vs[w]);
}
if(t==2){
int k;
cin>>k;
vector<int> xs(k);
for(int j=0;j<k;j++) cin>>xs[j];
for(int x:xs) G.set_vertex(vs[x],Vertex(1));
cout<<G.get_subtree(vs[xs[0]]).ans<<newl;
for(int x:xs) G.set_vertex(vs[x],Vertex(0));
}
}
return 0;
}