#include #include using namespace std; using namespace atcoder; typedef modint998244353 mint; typedef long long ll; int main(){ int n, q; cin >> n >> q; vector> ikeru(n, vector(0)); for (int i=0; i> a >> b; a--; b--; ikeru[a].push_back(b); ikeru[b].push_back(a); } vector> db(30, vector(n, -1)); vector mada = {~0, 0}; vector tansaku(n); tansaku[0] = 1; vector siz(n); vector depth(n); while(!mada.empty()){ int i = mada.back(); mada.pop_back(); if (i >= 0){ for (int j: ikeru[i]){ if (tansaku[j] == 0){ tansaku[j] = 1; db[0][j] = i; depth[j] = depth[i] + 1; mada.push_back(~j); mada.push_back(j); } } }else{ i = ~i; int tmp = 1; for (int j: ikeru[i]){ if (tansaku[j] == 2){ tmp += siz[j]; } } tansaku[i] = 2; siz[i] = tmp; } } for (int i=0; i<29; i++){ for (int j=0; j> s >> t; s--; t--; // lca int x = s, y = t; if (depth[x] < depth[y]){ swap(x, y); } int dist = 0; if (depth[x] > depth[y]){ int k = depth[x] - depth[y]; for (int j=0; j<30; j++){ if (k >> j & 1){ x = db[j][x]; dist += 1 << j; } } } if (x != y){ for (int j=29; j>=0; j--){ if (db[j][x] == -1) continue; if (db[j][x] != db[j][y]){ x = db[j][x]; y = db[j][y]; dist += 1 << j+1; } } } if (x != y){ x = db[0][x]; dist += 2; } if (dist % 2 == 1){ cout << 0 << "\n"; }else{ if (x == s || x == t){ if (x == t) swap(s, t); int w = t, g = dist / 2 - 1; for (int j=0; j<30; j++){ if (g >> j & 1){ w = db[j][w]; } } int ans = 0; ans -= siz[w]; w = db[0][w]; ans += siz[w]; cout << ans << "\n"; }else if(depth[s] != depth[t]){ if (depth[s] > depth[t]){ swap(s, t); } int w = t, g = dist / 2 - 1; for (int j=0; j<30; j++){ if (g >> j & 1){ w = db[j][w]; } } int ans = 0; ans -= siz[w]; w = db[0][w]; ans += siz[w]; cout << ans << "\n"; }else{ int v = t, w = s; int g = dist / 2 - 1; for (int j=0; j<30; j++){ if (g >> j & 1){ w = db[j][w]; v = db[j][v]; } } int ans = 0; ans = n; ans -= siz[w]; ans -= siz[v]; cout << ans << "\n"; } } } }