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 y=x[k]; int a=h.lca(p,y); while(p!=a){ p=nodes[p].parent; steps[stepn++]=p; } stepn+=nodes[y].depth-nodes[a].depth; int n=stepn; while(y!=a){ steps[--n]=y; y=nodes[y].parent; } p=x[k]; fs[stepn-1]=1; } } { int p=steps[0]; visited[p]=1; ll saved=0; rep(stepi,1,stepn){ int y=steps[stepi]; int localcost=(nodes[y].parent==p?nodes[y].cost:nodes[p].cost); saved+=localcost; totalcost+=localcost; if(visited[y]){ if(totalsaved