problemscpp
A collection of my answers to algorithm problems in c++.
静态 Public 成员函数 | 所有成员列表
leetcode::process_restricted_friend_requests::Solution类 参考

#include <leetcode.h>

静态 Public 成员函数

static vector< bool > friendRequests (int n, vector< vector< int > > &restrictions, vector< vector< int > > &requests)
 

详细描述

在文件 leetcode.h2109 行定义.

成员函数说明

◆ friendRequests()

vector< bool > leetcode::process_restricted_friend_requests::Solution::friendRequests ( int  n,
vector< vector< int > > &  restrictions,
vector< vector< int > > &  requests 
)
static

在文件 leetcode.cpp5689 行定义.

5689 {
5690 UnionFind uf(n);
5691 vector<bool> ans(requests.size());
5692 auto check = [&uf, &restrictions](int x, int y) -> bool {
5693 x = uf.find(x);
5694 y = uf.find(y);
5695 if(x > y) {
5696 swap(x, y);
5697 }
5698 for(auto &restriction: restrictions) {
5699 int i = uf.find(restriction[0]);
5700 int j = uf.find(restriction[1]);
5701 if(i > j) {
5702 swap(i, j);
5703 }
5704 if(i == x && j == y) {
5705 return false;
5706 }
5707 }
5708 return true;
5709 };
5710 for(int i = 0; i < requests.size(); i++) {
5711 if(check(requests[i][0], requests[i][1])) {
5712 uf.unite(requests[i][0], requests[i][1]);
5713 ans[i] = true;
5714 } else {
5715 ans[i] = false;
5716 }
5717 }
5718 return ans;
5719 }
并查集
Definition: templates.h:91

引用了 UnionFind::find() , 以及 UnionFind::unite().

被这些函数引用 leetcode::process_restricted_friend_requests::TEST().


该类的文档由以下文件生成: