2076. Process Restricted Friend Requests Hard
1/**
2 * [2076] Process Restricted Friend Requests
3 *
4 * You are given an integer n indicating the number of people in a network. Each person is labeled from 0 to n - 1.
5 * You are also given a 0-indexed 2D integer array restrictions, where restrictions[i] = [xi, yi] means that person xi and person yi cannot become friends, either directly or indirectly through other people.
6 * Initially, no one is friends with each other. You are given a list of friend requests as a 0-indexed 2D integer array requests, where requests[j] = [uj, vj] is a friend request between person uj and person vj.
7 * A friend request is successful if uj and vj can be friends. Each friend request is processed in the given order (i.e., requests[j] occurs before requests[j + 1]), and upon a successful request, uj and vj become direct friends for all future friend requests.
8 * Return a boolean array result, where each result[j] is true if the j^th friend request is successful or false if it is not.
9 * Note: If uj and vj are already direct friends, the request is still successful.
10 *
11 * Example 1:
12 *
13 * Input: n = 3, restrictions = [[0,1]], requests = [[0,2],[2,1]]
14 * Output: [true,false]
15 * Explanation:
16 * Request 0: Person 0 and person 2 can be friends, so they become direct friends.
17 * Request 1: Person 2 and person 1 cannot be friends since person 0 and person 1 would be indirect friends (1--2--0).
18 *
19 * Example 2:
20 *
21 * Input: n = 3, restrictions = [[0,1]], requests = [[1,2],[0,2]]
22 * Output: [true,false]
23 * Explanation:
24 * Request 0: Person 1 and person 2 can be friends, so they become direct friends.
25 * Request 1: Person 0 and person 2 cannot be friends since person 0 and person 1 would be indirect friends (0--2--1).
26 *
27 * Example 3:
28 *
29 * Input: n = 5, restrictions = [[0,1],[1,2],[2,3]], requests = [[0,4],[1,2],[3,1],[3,4]]
30 * Output: [true,false,true,false]
31 * Explanation:
32 * Request 0: Person 0 and person 4 can be friends, so they become direct friends.
33 * Request 1: Person 1 and person 2 cannot be friends since they are directly restricted.
34 * Request 2: Person 3 and person 1 can be friends, so they become direct friends.
35 * Request 3: Person 3 and person 4 cannot be friends since person 0 and person 1 would be indirect friends (0--4--3--1).
36 *
37 *
38 * Constraints:
39 *
40 * 2 <= n <= 1000
41 * 0 <= restrictions.length <= 1000
42 * restrictions[i].length == 2
43 * 0 <= xi, yi <= n - 1
44 * xi != yi
45 * 1 <= requests.length <= 1000
46 * requests[j].length == 2
47 * 0 <= uj, vj <= n - 1
48 * uj != vj
49 *
50 */
51pub struct Solution {}
52
53// problem: https://leetcode.com/problems/process-restricted-friend-requests/
54// discuss: https://leetcode.com/problems/process-restricted-friend-requests/discuss/?currentPage=1&orderBy=most_votes&query=
55
56// submission codes start here
57
58impl Solution {
59 pub fn friend_requests(n: i32, restrictions: Vec<Vec<i32>>, requests: Vec<Vec<i32>>) -> Vec<bool> {
60
61 }
62}
63
64// submission codes end
65
66#[cfg(test)]
67mod tests {
68 use super::*;
69
70 #[test]
71 fn test_2076() {
72 }
73}
74
Back
© 2025 bowen.ge All Rights Reserved.