#include <iostream>
#include <vector>
#include <cstdio>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <string.h>
#define ll long long int
#define l long int
#define pi pair<int,int>
#define pl pair<l,l>
#define pll pair<ll,ll>
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define MOD 1000000007
#define loop(i,n) for(int i=0;i<n;i++)
#define loop1(i,n) for(int i=1;i<=n;i++)
#define fast_input cin.tie(0);ios_base::sync_with_stdio(0);
using namespace std;
int parent[100005];
int siz[100005];
int root(int i)
{
while(parent[i]!=i)
{
parent[i]=parent[parent[i]];
i = parent[i];
}
return i;
}
void unionn(int x,int y)
{
int root_x = root(x);
int root_y = root(y);
if(siz[root_x]<siz[root_y])
{
parent[root_x]=root_y;
siz[root_y]+=siz[root_x];
}
else
{
parent[root_y]=root_x;
siz[root_x]+=siz[root_y];
}
}
bool findd(int x,int y)
{
if(root(x)==root(y))
return true;
else
return false;
}
int main()
{
int n;
scanf("%d",&n);
int color[n];
vector <int> adj[n];
loop(i,n)
{
parent[i]=i; ///initalising each member as its own parent ///
siz[i]=1; /// size of each group initailly all 1 ///
color[i]=-1; /// setting color -1 for all vertices ///
}
for(int i=0;i<n-1;i++)
{
int a,b;
scanf("%d %d",&a,&b);
adj[a].push_back(b); /// building up the graph(tree)///
adj[b].push_back(a);
}
int q;
scanf("%d",&q);
while(q--)
{
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
if(a==1)
{
color[b]=c;
for(int i=0;i<adj[b].size();i++)
{
int curr = adj[b][i]; /// connecting with DSU ///
if(color[curr]==color[b]) /// if color of neighbours are same///
{
unionn(curr,b);
}
}
}
else
{
if(findd(b,c)) /// if connect via DSU yes ///
printf("YES\n");
else
printf("NO\n");
}
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8Y3N0ZGlvPgojaW5jbHVkZSA8bWF0aC5oPgojaW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gIH0KICAgIGVsc2UKICAgIHsKICAgICAgICBwYXJlbnRbcm9vdF95XT1yb290X3g7CiAgICAgICAgc2l6W3Jvb3RfeF0rPXNpeltyb290X3ldOwogICAgfQp9CmJvb2wgZmluZGQoaW50IHgsaW50IHkpCnsKICAgIGlmKHJvb3QoeCk9PXJvb3QoeSkpCiAgICAgICAgcmV0dXJuIHRydWU7CiAgICBlbHNlCiAgICAgICAgcmV0dXJuIGZhbHNlOwp9CmludCBtYWluKCkKewogICAgaW50IG47CiAgICBzY2FuZigiJWQiLCZuKTsKICAgIGludCBjb2xvcltuXTsKICAgIHZlY3RvciA8aW50PiBhZGpbbl07CiAgICBsb29wKGksbikKICAgIHsKICAgICAgICBwYXJlbnRbaV09aTsgICAvLy9pbml0YWxpc2luZyBlYWNoIG1lbWJlciBhcyBpdHMgb3duIHBhcmVudCAvLy8KICAgICAgICBzaXpbaV09MTsgICAgICAvLy8gc2l6ZSBvZiBlYWNoIGdyb3VwIGluaXRhaWxseSBhbGwgMSAvLy8KICAgICAgICBjb2xvcltpXT0tMTsgICAvLy8gc2V0dGluZyBjb2xvciAtMSBmb3IgYWxsIHZlcnRpY2VzIC8vLwogICAgfQogICAgZm9yKGludCBpPTA7aTxuLTE7aSsrKQogICAgewogICAgICAgIGludCBhLGI7CiAgICAgICAgc2NhbmYoIiVkICVkIiwmYSwmYik7CiAgICAgICAgYWRqW2FdLnB1c2hfYmFjayhiKTsgICAgLy8vIGJ1aWxkaW5nIHVwIHRoZSBncmFwaCh0cmVlKS8vLwogICAgICAgIGFkaltiXS5wdXNoX2JhY2soYSk7CiAgICB9CiAgICBpbnQgcTsKICAgIHNjYW5mKCIlZCIsJnEpOwogICAgd2hpbGUocS0tKQogICAgewogICAgICAgIGludCBhLGIsYzsKICAgICAgICBzY2FuZigiJWQgJWQgJWQiLCZhLCZiLCZjKTsKICAgICAgICBpZihhPT0xKQogICAgICAgIHsKICAgICAgICAgICAgY29sb3JbYl09YzsKICAgICAgICAgICAgZm9yKGludCBpPTA7aTxhZGpbYl0uc2l6ZSgpO2krKykKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgaW50IGN1cnIgPSBhZGpbYl1baV07ICAgICAgICAvLy8gY29ubmVjdGluZyB3aXRoIERTVSAvLy8KICAgICAgICAgICAgICAgIGlmKGNvbG9yW2N1cnJdPT1jb2xvcltiXSkgICAgLy8vIGlmIGNvbG9yIG9mIG5laWdoYm91cnMgYXJlIHNhbWUvLy8KICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICB1bmlvbm4oY3VycixiKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBlbHNlCiAgICAgICAgewogICAgICAgICAgICBpZihmaW5kZChiLGMpKSAgICAgICAgICAgICAgIC8vLyBpZiBjb25uZWN0IHZpYSBEU1UgeWVzICAvLy8KICAgICAgICAgICAgICAgIHByaW50ZigiWUVTXG4iKTsKICAgICAgICAgICAgZWxzZQogICAgICAgICAgICAgICAgcHJpbnRmKCJOT1xuIik7CiAgICAgICAgfQogICAgfQogICAgcmV0dXJuIDA7Cn0K