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

#include <leetcode.h>

Public 成员函数

void dfs (bool *dfsd, int v, int i)
 
vector< vector< int > > getAncestors (int n, vector< vector< int > > &edges)
 

Private 属性

unordered_map< int, set< int > > ancestors
 
unordered_map< int, unordered_set< int > > nexts
 

详细描述

在文件 leetcode.h1500 行定义.

成员函数说明

◆ dfs()

void leetcode::all_ancestors_of_a_node_in_a_directed_acyclic_graph::Solution::dfs ( bool *  dfsd,
int  v,
int  i 
)

在文件 leetcode.cpp3886 行定义.

3886 {
3887 ancestors[i].insert(v);
3888 dfsd[i] = true;
3889 for(const auto next: nexts[i]) {
3890 if(!dfsd[next]) {
3891 dfs(dfsd, v, next);
3892 }
3893 }
3894 }

引用了 ancestors, dfs() , 以及 nexts.

被这些函数引用 dfs() , 以及 getAncestors().

◆ getAncestors()

vector< vector< int > > leetcode::all_ancestors_of_a_node_in_a_directed_acyclic_graph::Solution::getAncestors ( int  n,
vector< vector< int > > &  edges 
)

在文件 leetcode.cpp3859 行定义.

3859 {
3860 for(int i = 0; i < n; i++) {
3861 nexts[i] = unordered_set<int>();
3862 ancestors[i] = set<int>();
3863 }
3864 for(auto edge: edges) {
3865 nexts[edge[0]].insert(edge[1]);
3866 }
3867 for(int i = 0; i < n; i++) {
3868 for(const auto next: nexts[i]) {
3869 auto *dfsd = new bool[n];
3870 memset(dfsd, 0, n * sizeof(bool));
3871 dfs(dfsd, i, next);
3872 delete[] dfsd;
3873 }
3874 }
3875 vector<vector<int>> ans;
3876 for(int i = 0; i < n; i++) {
3877 vector<int> vec;
3878 for(auto i: ancestors[i]) {
3879 vec.push_back(i);
3880 }
3881 ans.push_back(vec);
3882 }
3883 return ans;
3884 }
int vec[100010]
Definition: pat.cpp:5095

引用了 ancestors, dfs(), nexts , 以及 pat::a::a7_2::vec.

类成员变量说明

◆ ancestors

unordered_map<int, set<int> > leetcode::all_ancestors_of_a_node_in_a_directed_acyclic_graph::Solution::ancestors
private

在文件 leetcode.h1502 行定义.

被这些函数引用 dfs() , 以及 getAncestors().

◆ nexts

unordered_map<int, unordered_set<int> > leetcode::all_ancestors_of_a_node_in_a_directed_acyclic_graph::Solution::nexts
private

在文件 leetcode.h1501 行定义.

被这些函数引用 dfs() , 以及 getAncestors().


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