哈哈哈!!!

using namespace std;
const int N =20005;
int f[N];
int find(int x)
{
	while(x!=f[x])
	{
		x=f[x];
	}
	return x;
} 
int main()
{
	map<string,int> st;
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		f[i]=i;
	}
	for(int j=1;j<=n;j++)
	{
		string s;
		cin>>s;
		st[s]=j;
	}
	for(int i=1;i<=m;i++)
	{
		int x;
		cin>>x;
		string b,c;
		cin>>b>>c;
		if(x==1)
		{
			f[find(st[c])]=find(st[b]);
		}
		else 
		{
			if(find(st[b])!=find(st[c]))
			{
				cout<<0<<endl;
			}
			else 
			{
				cout<<1<<endl;
			}
		}
	}
	return 0;
}