//并查集的模板题,写个并查集完事 #include <bits/stdc++.h> using namespace std; map<string , string> mp; string find(string s) { return mp[s]==s? s:mp[s] = find(mp[s]); } void merge(string s1, string s2) { string g1 = find(s1); string g2 = find(s2); if (g1!=g2) mp[g1] = g2; } int main() { int n, m, opt; string name; string p1, p2; cin>>n>>m; //先让初始的根节点为他自己。 for (int i=0;i<n;i++) { cin>>name; mp[name] = name; } while (m--) { cin>>opt; cin>>p1>>p2; if (opt == 1) { merge(p1, p2); } if (opt==2) { if (find(p1)==find(p2)) cout<<1<<endl; else cout<<0<<endl; } } return 0; }