int u[3d3],v[3d3],l[3d3],x[3d3]; struct Node { int parent; int depth; ll cost; }; Node nodes[3d3]; int visited[3d3]; ll saveds[3d3]; int steps[10000000],fs[10000000]; int stepn; ll totalcost; ll totalsaved; wgraph g; //HLD h; void f1(int i,int p){ rep(k,g.es[i]){ int j=g.edge[i][k]; if(j!=p){ nodes[j].parent=i; nodes[j].depth=nodes[i].depth+1; nodes[j].cost=g.cost[i][k]; f1(j,i); } } } { int @n,@q,@c; rd((u--,v--,l)(n-1)); rd((x--)(q)); g.setEdge(n,n-1,u,v,l); //h.init(g.g); f1(0,-1); { int p=x[0]; steps[stepn++]=p; rep(k,q){ int a=p; int y=x[k]; //wt("hoge"); //wt(a,y,nodes[a].depth,nodes[y].depth); while(nodes[a].depth>nodes[y].depth){ a=nodes[a].parent; } //wt(a,y,nodes[a].depth,nodes[y].depth); while(nodes[a].depth