#include typedef struct list { int v; struct list *n; } list; int func (int v, int tmpd, int tmpp, int tmpi, list **e, int *d, int p[][20], int idx[][2], int *size, int *visited, int **chidx, int *chidx_arr, int *ch, int *chcnt) { list *l = e[v]; visited[v] = 1; d[v] = tmpd; p[v][0] = tmpp; idx[v][0] = tmpi; size[v] = 1; chidx[v] = chidx_arr+(*chcnt); ch[v] = 0; while (l != NULL) { if (visited[l->v] <= 0) { ch[v]++; } l = l->n; } *chcnt += ch[v]; l = e[v]; ch[v] = 0; while (l != NULL) { if (visited[l->v] <= 0) { tmpi = func(l->v, tmpd+1, v, tmpi+1, e, d, p, idx, size, visited, chidx, chidx_arr, ch, chcnt); size[v] += size[l->v]; chidx[v][ch[v]] = l->v; ch[v]++; } l = l->n; } tmpi++; idx[v][1] = tmpi; return tmpi; } int main () { int n = 0; int q = 0; int a = 0; int b = 0; int s = 0; int t = 0; int res = 0; int d[200000] = {}; int size[200000] = {}; int p[200000][20] = {}; list pool[399998] = {}; int used = 0; list *e[200000] = {}; int visited[200000] = {}; int idx[200000][2] = {}; int *chidx[200000] = {}; int chidx_arr[200000] = {}; int ch[200000] = {}; int chcnt = 0; res = scanf("%d", &n); res = scanf("%d", &q); for (int i = 0; i < n-1; i++) { res = scanf("%d", &a); res = scanf("%d", &b); a--; b--; pool[used].v = b; pool[used].n = e[a]; e[a] = pool+used; used++; pool[used].v = a; pool[used].n = e[b]; e[b] = pool+used; used++; } res = func(0, 0, 0, 0, e, d, p, idx, size, visited, chidx, chidx_arr, ch, &chcnt); for (int i = 1; i < 20; i++) { for (int j = 0; j < n; j++) { p[j][i] = p[p[j][i-1]][i-1]; } } while (q > 0) { res = scanf("%d", &s); res = scanf("%d", &t); s--; t--; if (d[s]%2 != d[t]%2) { printf("0\n"); } else { int ps = s; int pt = t; int bit = 19; while (bit >= 0) { if (p[ps][bit] != p[pt][bit]) { ps = p[ps][bit]; pt = p[pt][bit]; } bit--; } ps = p[ps][0]; pt = p[pt][0]; if (d[s] == d[t]) { int ans = n; int r[2] = { 0, ch[ps] }; while (r[1]-r[0] > 1) { int nxt = (r[0]+r[1])/2; if (idx[chidx[ps][nxt]][0] <= idx[s][0]) { r[0] = nxt; } else { r[1] = nxt; } } ans -= size[chidx[ps][r[0]]]; r[0] = 0; r[1] = ch[ps]; while (r[1]-r[0] > 1) { int nxt = (r[0]+r[1])/2; if (idx[chidx[ps][nxt]][0] <= idx[t][0]) { r[0] = nxt; } else { r[1] = nxt; } } ans -= size[chidx[ps][r[0]]]; printf("%d\n", ans); } else { int pd = 0; int cnt = s; int r[2] = {}; int ans = 0; if (d[s] < d[t]) { int swap = s; s = t; t = swap; } pd = d[s]-d[ps]-(d[s]-d[t])/2; for (int i = 0; i < 20; i++) { if ((pd&(1< 0) { cnt = p[cnt][i]; } } r[0] = 0; r[1] = ch[cnt]; while (r[1]-r[0] > 1) { int nxt = (r[0]+r[1])/2; if (idx[chidx[cnt][nxt]][0] <= idx[s][0]) { r[0] = nxt; } else { r[1] = nxt; } } ans = size[cnt]; ans -= size[chidx[cnt][r[0]]]; printf("%d\n", ans); } } q--; } return 0; }