#include "bits/stdc++.h"
#include "infection.h"
// #include "grader.cpp"
using namespace std;
#define ll long long
#define pii pair<int, int>
#define ff first
#define ss second
#define pb push_back
const int N = 2e5+5;
vector<int> adj[N];

vector<int> solve(vector<pii> R, vector<ll> D, vector<int> S, vector<int> T, vector<bool> I){
    int n=(int)R.size()+1;
    for(int i = 0; i < n-1; ++i){
        adj[R[i].ff+1].pb(R[i].ss+1);
        adj[R[i].ss+1].pb(R[i].ff+1);
    }
    vector<bool> have(n, 0);
    int m=(int)D.size();
    vector<int> ans(m, 0);
    for(int ad = 0; ad < m; ++ad){
        if(I[ad]==1){
            have[S[ad]]=1, ans[ad]=abs(S[ad]-T[ad])+1;
            continue;
        }
        assert(I[ad]==0);
        if(have[S[ad]])
            ans[ad]=abs(S[ad]-T[ad])+1;
    }
    return ans;
}