#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
std::vector<int> solve(
std::vector<std::pair<int, int>> R,
std::vector<long long> D,
std::vector<int> S,
std::vector<int> T,
std::vector<bool> I
) {
    for (auto &[i, j] : R) i++, j++;
    for (auto &i : S) i++;
    for (auto &i : T) i++;
    int n = R.size() + 1;
    vector<int> g[n + 1];
    for (auto [i, j] : R) {
        g[i].push_back(j);
        g[j].push_back(i);
    }
    map<long long, vector<pair<int, int>>> mp;
    int m = S.size();
    vector<int> ans(m);
    vector<int> parent(n + 1);
    function<void(int, int)> dfs = [&](int v, int p) {
        parent[v] = p;
        for (auto to : g[v]) {
            if (to == p) continue;
            dfs(to, v);
        }
        return;
    };
    vector<int> way[n + 1];
    map<int, vector<int>> mp;
    vector<pair<int, int>> q;
    for (int i = 0; i < m; ++i) {
        int st = S[i], fn = T[i];
        dfs(fn, 0);
        while (true) {
            way[i].push_back(st);
            if (st == fn) break;
            st = parent[st];
        }
        int len = way.size();
        /*for (long long j = 0; j < len; ++j) {
            mp[j + D[i]].push_back({way[j], i});
        }*/
        q.push_back({D[i], D[i] + len - 1);
        mp[D[i]].push_back(i);
        mp[len + D[i]].push_back(-i);
    }
    sort(q.begin(), q.end());
    int last = -1e9;
    vector<bool> mapa(n + 10);
    set<int> now;
    for (auto [l, r] : q) {
        last = max(last + 1, l);
        if (last <= r) {
            for (int i = last; i <= r; ++i) {
                if (mp.find(i) != mp.end()) {
                    for (auto key : mp[i]) {
                        if (key < 0) now.erase(-key);
                        else now.insert(key);
                    }
                }
                for (auto key : now) mapa[key] = false;
                for (auto key : now) mapa[]
            }
        } 
        last = max(last, r);
    }
    
    /*for (auto [key, vec] : mp) {
        for (auto [ver, idx] : vec) mapa[ver] = false;
        for (auto [ver, idx] : vec) {
            mapa[ver] = mapa[ver] | I[idx];
        }
        for (auto [ver, idx] : vec) {
            if (mapa[ver]) I[idx] = true;
            ans[idx] += I[idx];
        }
    }*/
    return ans;
}
/*signed main() {
    vector<int> ans = solve(
        {{0, 1}, {1, 2}, {2, 3}, {3, 4}, {3, 6}, {6, 7}, {6, 8}, {4, 5}},
        {1, 3, 4, 8, 10},

        {0, 5, 5, 7, 0},
        {5, 7, 7, 8, 1},
        {1, 0, 0, 0, 0}
        );
        for (auto i : ans) cout << i << ' ';
    return 0;
}*/
