本文整理汇总了C++中AdjacencyList::NumVertices方法的典型用法代码示例。如果您正苦于以下问题:C++ AdjacencyList::NumVertices方法的具体用法?C++ AdjacencyList::NumVertices怎么用?C++ AdjacencyList::NumVertices使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AdjacencyList
的用法示例。
在下文中一共展示了AdjacencyList::NumVertices方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: StronglyConnectedComponents
void StronglyConnectedComponents(const AdjacencyList& graph,
std::vector<int>& cc) {
cc.resize(graph.NumVertices());
const AdjacencyList& reverse_graph = Reverse(graph);
vector<Vertex> sorted;
TopologicalSort(reverse_graph, sorted);
vector<bool> visited(graph.NumVertices(), false);
int cc_num = 1;
for (Vertex u : sorted) {
if (!visited[u]) {
cc[u] = cc_num++;
Explore(graph, u, visited, cc);
}
}
}
示例2: Reverse
AdjacencyList Reverse(const AdjacencyList& graph) {
size_t n = graph.NumVertices();
AdjacencyList rg(n);
for (Vertex u = 0; u < n; ++u) {
for (const Neighbor& neighbor : graph.GetNeighbors(u)) {
Vertex v;
double ignored_cost;
std::tie(v, ignored_cost) = neighbor;
rg.AddEdge(v, u);
}
}
return rg;
}
示例3: TopologicalSort
void TopologicalSort(const AdjacencyList& graph,
vector<Vertex>& sorted) {
size_t n = graph.NumVertices();
vector<bool> visited(n, false);
for (size_t i = 0; i < n; ++i) {
if (!visited[i]) {
Explore(graph, i, visited, sorted);
}
}
// By the time DFS finished, nodes in *sorted* are in increasing
// order in terms of finishing time. Reverse it to get topological
// ordering.
std::reverse(sorted.begin(), sorted.end());
}