#include #include #include using namespace std; int main() { // 【重要】これがないと C++ でも TLE する可能性があります ios_base::sync_with_stdio(false); cin.tie(NULL); int N, Q; if (!(cin >> N >> Q)) return 0; // 1. 木の辺を読み込んで S を構築 string S = ""; S.reserve(N - 1); // メモリをあらかじめ確保して高速化 for (int i = 0; i < N - 1; i++) { int u, v; cin >> u >> v; if (u < v) { S += '0'; } else { S += '1'; } } // S を一気に出力してフラッシュ cout << S << endl; // 2. クエリに答える for (int i = 0; i < Q; i++) { int c, d; if (!(cin >> c >> d)) break; if (c < d) { cout << 0 << endl; // endl は flush を含むのでインタラクティブに適しています } else { cout << 1 << endl; } } return 0; }