#include using namespace std; typedef long long int ll; typedef pair P; typedef vector VI; typedef vector VVI; #define REP(i,n) for(int i=0;i<(n);i++) #define ALL(v) v.begin(),v.end() template bool chmax(T& x, const T& y){return (x bool chmin(T& x, const T& y){return (x>y)?(x=y,true):false;}; constexpr ll MOD=998244353; constexpr ll INF=2e18; int main(){ int n, q; cin >> n >> q; VVI g(n); int a, b; REP(i,n-1){ cin >> a >> b; a--, b--; g[a].push_back(b); g[b].push_back(a); } VI dist(n); function dfs=[&](int v, int p, bool d){ dist[v]=d; for(auto to:g[v]){ if(to==p) continue; dfs(to,v,!d); } }; dfs(0,-1,0); int s, t; REP(i,q){ cin >> s >> t; s--, t--; if(dist[s]==dist[t]) cout << 1 << endl; else cout << 0 << endl; } return 0; }