voidunionset(string a, string b){ if (unionFindSet.find(a) == unionFindSet.end()) unionFindSet[a] = a; if (unionFindSet.find(b) == unionFindSet.end()) unionFindSet[b] = b; unionFindSet[find(unionFindSet[a])] = find(unionFindSet[b]); }
boolcompany(string a, string b){ if (unionFindSet.find(a) == unionFindSet.end() || unionFindSet.find(b) == unionFindSet.end()) returnfalse; returnfind(unionFindSet[a]) == find(unionFindSet[b]); }
intmain(){ int N = 0; cin >> N; for (int i = 0; i < N; i++) { int op = 0; string a, b; cin >> op >> a >> b; if (op) cout << (company(a, b) ? "yes" : "no") << endl; else unionset(a, b); }