本文整理汇总了C++中graph::size方法的典型用法代码示例。如果您正苦于以下问题:C++ graph::size方法的具体用法?C++ graph::size怎么用?C++ graph::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类graph
的用法示例。
在下文中一共展示了graph::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dijkstra
int dijkstra(const graph &g, int src, int forbidden, const vi &costTable,
int limitation) {
pq queue;
queue.push(make_pair(0, src));
vi output(g.size());
fill(output.begin(), output.end(), INF);
while (!queue.empty() && output[g.size()-1] == INF) {
pii p = queue.top();
queue.pop();
int cost = p.first;
int index = p.second;
if (output[index] != INF) {
continue;
}
output[index] = cost;
for (int i = 0; i < g[index].size(); i++) {
int nextIndex = g[index][i];
if (output[nextIndex] != INF) {
continue;
}
if (index == src && nextIndex == forbidden) {
continue;
}
if (cost+1+costTable[nextIndex] > limitation) {
continue;
}
queue.push(make_pair(cost+1, nextIndex));
}
}
return output[g.size()-1];
}
示例2: daiquistra
vector<int> daiquistra(graph& g, int v){
vector<int> dist(g.size(), INT_MAX);
vector<int> prev(g.size(), -1);
dist[v] = 0;
set<pair<int, int> > q;
for(int i = 0; i<g.size(); i++){
q.insert(make_pair(dist[i], i));
}
while(!q.empty()){
int u = q.begin()->second;
int p = q.begin()->first;
q.erase(q.begin());
if(dist[u] == INT_MAX)
break;
for(int i = 0; i<g[u].size(); i++){
int w = g[u][i].second;
int alt = dist[u] + g[u][i].first;
if(alt < dist[w]){
q.erase(make_pair(dist[w], w));
dist[w] = alt;
prev[w] = u;
q.insert(make_pair(dist[w], w));
}
}
}
return prev;
}
示例3: bfs
vector<ulong> bfs(graph g, ulong source_node) {
vector<bool> v_bool_visited = vector<bool>(g.size() + 1, false);
v_bool_visited[source_node] = true;
vector<ulong> m_shortest_path = vector<ulong>(g.size() + 1, ULONG_MAX);
m_shortest_path[source_node] = 0;
queue<int> q;
for (ulong i = 0; i < g[source_node].size(); i++) {
q.push(g[source_node][i]);
}
while (q.size() > 0) {
ulong node = q.front();
q.pop();
cout << "Processing node: " << node << endl;
vector<ulong> v_neighbors = g[node];
for(ulong i = 0; i < v_neighbors.size(); i++)
{
if(!v_bool_visited[i]) {
q.push(v_neighbors[i]);
if(m_shortest_path[v_neighbors[i]] == ULONG_MAX)
m_shortest_path[v_neighbors[i]] = m_shortest_path[node] + 1;
}
}
v_bool_visited[node] = true;
}
return m_shortest_path;
}
示例4: dfs
void dfs(graph &g){
int tempo = 0;
vector<int> t(g.size()), d(g.size()), c(g.size(), branco), antec(g.size(), -1);
for(int i = 0; i<g.size(); i++){
if(c[i] == branco)
vdfs(g, i, t, d, c, tempo, antec);
}
}
示例5: seller_ant
bool seller_ant(const graph& gr, const int start, const int finish /*nobody cares about that*/, Ant::way& out_way) {
size_t total_visited = 0, cnt_visited = 0;
std::vector < int > visited(gr.size(), 0);
const size_t operation_limit = std::min(
static_cast<size_t>(gr.size() * std::pow(gr.size(), 3.0/2)),
gr.get_number_of_edges() * 2
) * 5;
return comv_dfs(start, gr, static_cast<double>(GREEDY_NUM) / GREEDY_DENOM,
static_cast<double>(SWEET_TOOTH_NUM) / SWEET_TOOTH_DENOM, total_visited, operation_limit , visited,
cnt_visited, 0, out_way, static_cast<double>(RAND_NUM) / RAND_DENOM) == Comv_res::FOUND;
}
示例6: solve
int solve(const graph &g, int w) {
vi costTable;
for (int i = 0; i < g.size(); i++) {
costTable.push_back(dijkstraStartFromRoomWithBrokenDoor(g, i, w));
}
for (int i = 0; i < 2*g.size(); i++) {
if (reachableWithLimitation(g, costTable, i)) {
return i;
}
}
return -1;
}
示例7: bfs
vector<int> bfs(graph& g){
vector<int> dist(g.size(), INT_MAX);
vector<int> c(g.size(), branco);
vector<int> antec(g.size(), -1);
for(int i = 0; i<g.size(); i++){
if(c[i] == branco){
vbfs(g, i, dist, c, antec);
}
}
return antec;
}
示例8: troiscoloriable
bool troiscoloriable(graph & g) {
vector<int> coul(g.size(), -1);
int i, j;
for (i = 0; i < (int) g.size(); ++i) {
++coul[i];
if (coul[i] > 2) return false; // Limite de couleur atteinte
for (j = 0; j < (int) g[i].size(); ++j) {
if (coul[g[i][j]] == coul[i])
{ --i; break; } // Backtrack
}
}
return true;
}
示例9: costoUniforme
int costoUniforme() {
int size = G.size();
p_queue pq;
map<pair<int, char>, bool> visited;
pq.push(ici(0, 0, start));
while(!pq.empty()) {
ici state = pq.top();
pq.pop();
int u = state.second.second;
char prevch = state.second.first;
if(visited.find(make_pair(u, prevch)) != visited.end()) continue;
if(u == end) return state.first;
visited[make_pair(u, prevch)] = true;
edges& adj = G[u];
for(int i = 0; i < adj.size(); i++) {
int v = adj[i].first;
char currch = adj[i].second.first;
if(currch == prevch) continue;
if(visited.find(make_pair(v, currch)) == visited.end()) {
pq.push(ici(state.first + adj[i].second.second, currch, v));
}
}
}
return INF;
}
示例10: dijkstra
int dijkstra() {
int size = G.size();
vector<int> dist(size, INF);
vector<int> prev(size, -1);
vector<bool> visited(size, false);
vector<char> fromch(size, -1);
dist[start] = 0;
fromch[start] = 0;
for(int i = 0; i < size; i++) {
int idx = -1;
for(int j = 0; j < size; j++) if(!visited[j]) {
if(idx == -1 || dist[idx] > dist[j])
idx = j;
}
visited[idx] = true;
char pch = fromch[idx];
edges& adj = G[idx];
D(pch);
for(int j = 0; j < size; j++) {
ici state = adj[j];
if(pch == state.second.first) continue;
if(dist[idx]+state.second.second < dist[state.first]) {
dist[state.first] = dist[idx] + state.second.second;
prev[state.first] = idx;
fromch[state.first] = state.second.first;
}
}
}
return dist[end];
}
示例11: dijkstra
void dijkstra (graph g, int u, int v){
priority_queue<int> fila;
vector<int> visited;
int element, cost, atual;
visited.resize (g.size(), max);
visited[u] = 0;
fila.push (u);
while (!fila.empty()){
atual = fila.top();
fila.pop();
for (int i=0; i<g[atual].size(); i++){
element = g[atual][i].first;
cost = g[atual][i].second;
if (visited[element] > visited[atual] + cost){
visited[element] = visited[atual] + cost;
fila.push (element);
}
}
}
cout << visited[v];
}
示例12: maximum_matching
int maximum_matching(const graph &g, vector<pair<int,int>> &matching) {
int n = g.size();
vector<int> mu(n), phi(n), rho(n), scanned(n);
rep(v,n) mu[v] = phi[v] = rho[v] = v;
for(int x = -1;;) {
if(x < 0) {
for(x = 0; x < n && (scanned[x] || !EVEN(x)); ++x);
if(x == n) break;
}
int y = -1;
for(auto &e: g[x]) if(OUTER(e) || (EVEN(e) && rho[e] != rho[x])) y = e;
if(y == -1) scanned[x] = true, x = -1;
else if(OUTER(y)) phi[y] = x;
else {
vector<int> dx(n,-2), dy(n,-2);
for(int k = 0, w = x; dx[w] < 0; w = k%2 ? mu[w] : phi[w]) dx[w] = k++;
for(int k = 0, w = y; dy[w] < 0; w = k%2 ? mu[w] : phi[w]) dy[w] = k++;
bool vertex_disjoint = true;
rep(v,n) if(dx[v] >= 0 && dy[v] > 0) vertex_disjoint = false;
if(vertex_disjoint) {
rep(v,n) if(dx[v] % 2 or dy[v] % 2) mu[phi[v]] = v, mu[v] = phi[v];
mu[x] = y; mu[y] = x; x = -1;
rep(v,n) phi[v] = rho[v] = v, scanned[v] = false;
}
else {
int r = x , d = n;
rep(v,n) if(dx[v] >= 0 && dy[v] >= 0 && rho[v] == v && d > dx[v]) d = dx[v], r = v;
rep(v,n) if((dx[v] <= d && dx[v] % 2 && rho[phi[v]] != r) || (dy[v] <= d && dy[v] % 2 && rho[phi[v]] != r)) phi[phi[v]] = v;
if(rho[x] != r) phi[x] = y;
if(rho[y] != r) phi[y] = x;
rep(v,n) if(dx[rho[v]] >= 0 || dy[rho[v]] >= 0) rho[v] = r;
}
}
}
示例13: uncoloriable
bool uncoloriable(graph & g) {
int i;
for (i = 0; i < (int) g.size(); ++i) {
if (g[i].size() != 0)
return false;
}
return true;
}
示例14: is_eulerian
bool is_eulerian(graph &adj){
int n = adj.size();
for(int v = 0; v < n; v++){
if(adj[v].size() % 2 == 1){
return false;
}
}
return true;
}
示例15: ps
pair<predecessors, distances> dijkstra(const graph &g, int from) {
predecessors ps(g.size(), -1);
distances ds(g.size(), INT_MAX);
ds[from] = 0;
vector<bool> processed(g.size(), false);
for(int i = 0; i < g.size(); i++) {
int v = minDistance(ds, processed);
processed[v] = true;
for(edge e : g[v]) {
if(ds[e.first] > ds[v] + e.second) {
ds[e.first] = ds[v] + e.second;
ps[e.first] = v;
}
}
}
return {ps, ds};
}