Union-Find
Code\nrust []\nuse std::cell::Cell;\n\n#[derive(Debug)]\nstruct Node {\n\tparent : Cell<u32>, // using Cell so find only takes a &self and not a &mut self (not 
# Code\n```rust []\nuse std::cell::Cell;\n\n#[derive(Debug)]\nstruct Node {\n\tparent : Cell<u32>, // using Cell so find only takes a &self and not a &mut self (not that it matters much, its just nicer)\n    size : i32,\n}\n\n#[derive(Debug)]\nstruct UF {\n    data : Vec<Node>,\n}\n\nimpl UF {\n    fn new(n : usize) -> Self {\n        assert!(n <= u32::MAX as usize);\n        let mut data = Vec::with_capacity(n);\n        for i in 0..n {\n            data.push(Node { parent: Cell::new(i as u32), size: 1, });\n        }\n        return Self { data, };\n    }\n    fn find<U : TryInto<usize>>(&self, i : U) -> usize {\n        let i : usize = i.try_into().unwrap_or(usize::MAX); // :-)\n        fn find_mono(this : &UF, i : usize) -> usize {\n            if this.data[i].parent.get() as usize == i {\n                return i;\n            }\n            let sub = this.find(this.data[i].parent.get() as usize);\n            this.data[i].parent.set(sub as u32);\n            return sub;\n        }\n        find_mono(self, i)\n    }\n    fn union<U1 : TryInto<usize>, U2 : TryInto<usize>>(&mut self, i : U1, j : U2) {\n        let i : usize = i.try_into().unwrap_or(usize::MAX); // :-)\n        let j : usize = j.try_into().unwrap_or(usize::MAX); // :-)\n        fn union_mono(this : &mut UF, i : usize, j : usize) {\n            let sub1 = this.find(i);\n            let sub2 = this.find(j);\n            if sub1 == sub2 {\n                return;\n            }\n            let sz1 = this.data[sub1].size;\n            let sz2 = this.data[sub2].size;\n            if sz1 < sz2 {\n                this.data[sub1].parent.set(sub2 as u32);\n                this.data[sub2].size += sz1;\n            } else {\n                this.data[sub2].parent.set(sub1 as u32);\n                this.data[sub1].size += sz2;\n            }\n        }\n        union_mono(self, i, j)\n    }\n}\n\nuse std::cmp::*;\nimpl Solution {\n    // O(n + |restrictions| * |requests| * alpha(n))\n    pub fn friend_requests(n: i32, restrictions: Vec<Vec<i32>>, requests: Vec<Vec<i32>>) -> Vec<bool> {\n        let mut uf = UF::new(n as usize);\n        let mut ans = Vec::with_capacity(requests.len());\n        for request in requests {\n            let i1 = uf.find(request[0]);\n            let i2 = uf.find(request[1]);\n            let (i1, i2) = (min(i1, i2), max(i1, i2));\n            let mut conflict = false;\n            for restriction in restrictions.iter() {\n                let r1 = uf.find(restriction[0]);\n                let r2 = uf.find(restriction[1]);\n                let (r1, r2) = (min(r1, r2), max(r1, r2));\n                if i1 == r1 && i2 == r2 {\n                    conflict = true;\n                    break;\n                }\n            }\n            if conflict {\n                ans.push(false);\n            } else {\n                uf.union(i1, i2);\n                ans.push(true);\n            }\n        }\n        return ans;\n    }\n}\n```
['Union Find', 'Rust']