We’re preparing your current view and syncing the latest data.
You are given a list of n people numbered from 0 to n - 1 and two lists: restrictions and friendRequests. Each restriction is a pair [x, y] indicating that x and y cannot be in the same friend group. Each friend request is a pair [u, v] representing a request to become friends. Your task is to process the requests in order and determine for each request if it can be accepted without violating any restriction. If a request can be accepted, the two friend groups should be merged, otherwise the request is rejected. Return a boolean array answer where answer[i] is true if the ith friend request is accepted, and false if it is rejected.
An integer n, an array of restrictions, and an array of friend requests.
Return an array of boolean values indicating which friend requests are accepted.
1 <= n <= 1000, 0 <= restrictions.length, friendRequests.length <= 1000, 0 <= x, y, u, v < n
Example 1
Input
n = 3 restrictions = [[0,1]] friendRequests = [[0,2],[2,1]]
Output
[true,false]
Explanation
First request merges groups {0} and {2} which is allowed. The second request merges groups {0,2} and {1}, but 0 and 1 are restricted, so the request is rejected.