5
public boolean[] friendRequests(int n, int[][] restrictions, int[][] requests) {7
for (int i = 0; i < n; i++) {10
result = new boolean[requests.length];12
for (int i = 0; i < requests.length; i++) {13
// personA and personB can become friends if for all restrictions14
// person x_i and person y_i are not in the same set as personA and personB16
int personA = requests[i][0];17
int personB = requests[i][1];18
int personASetRepresentative = find(personA);19
int personBSetRepresentative = find(personB);21
for (int[] restriction : restrictions) {22
int blackListPersonARepresentative = find(restriction[0]);23
int blackListPersonBRepresentative = find(restriction[1]);24
if (personASetRepresentative == blackListPersonARepresentative25
&& personBSetRepresentative == blackListPersonBRepresentative) {28
if (personASetRepresentative == blackListPersonBRepresentative29
&& personBSetRepresentative == blackListPersonARepresentative) {34
union(personA, personB);41
private int find(int node) {43
while (parent[root] != root) {49
while (parent[curr] != root) {50
int next = parent[curr];57
private boolean union(int node1, int node2) {58
int root1 = find(node1);59
int root2 = find(node2);63
parent[root2] = root1;