#include #include #include using namespace std; #define MAX_V 100000 #define MAX_LOG_V 17 vector G[MAX_V]; int root=0; int parent[MAX_LOG_V][MAX_V]; int depth[MAX_V]; void dfs(int v, int p, int d){ parent[0][v]=p; depth[v]=d; for(auto &e:G[v]){ if(e!=p) dfs(e,v,d+1); } } void init(int V){ dfs(root,-1,0); for(int k=0;k+1depth[v])swap(u,v); for(int k=0;k>k&1) v=parent[k][v]; } if(u==v) return u; for(int k=MAX_LOG_V-1;k>=0;k--){ if(parent[k][u]!=parent[k][v]){ u=parent[k][u]; v=parent[k][v]; } } return parent[0][u]; } int go[MAX_V]; int turn[MAX_V]; int path[MAX_V]; int dfs2(int v, int p){ int n=go[v]; for(auto &e:G[v]){ if(e!=p) n+=dfs2(e,v); } path[v]=n-turn[v]; return n-2*turn[v]; } int main(){ int N; cin>>N; for(int i=1;i>u>>v; G[u-1].push_back(v-1); G[v-1].push_back(u-1); } init(N); int Q; cin>>Q; for(int i=0;i>A>>B; A--;B--; turn[lca(A,B)]++; go[A]++;go[B]++; } dfs2(0,-1); long long int ans=0; for(int i=0;i