/* * N * u1 v1 * .. * un vn * Q : Q people * A1 B1 * .. * AQ BQ */ #include "stdio.h" int node[16384][16384]; int a[16384], b[16384], tax[16384]; int taxsum = 0; void push(u,v) { ++node[u][0]; node[u][node[u][0]] = v; } void pay(t) { taxsum += t; } int search(u,v,parent,m) // @u search v -> returns the #edge between u,v { int i,ret=1; pay(++tax[u]); for (i=1;i<=node[u][0];i++){ //printf("now marchant %d is in village %d and the tax is %d. the sum of tax is %d\n",m,u,tax[u],taxsum); if (parent == node[u][i]) continue; else if (node[u][i] == v) { pay(++tax[v]); return ret; } else ret += search(node[u][i],v,u,m); } pay(-(--tax[u])); return 0; } int main(int argc, char** argv) { int i,j,n,u,v,q; scanf("%d", &n); for (i=1; i <= n-1; i++) { scanf("%d%d", &u, &v); push(u,v); push(v,u); } //for (i=1;i<=n;i++) //{ // for (j=1;j<=node[i][0];j++) // printf("%d ", node[i][j]); // printf("\n"); //} scanf("%d", &q); for (i=0; i