本文整理汇总了C++中vvii::size方法的典型用法代码示例。如果您正苦于以下问题:C++ vvii::size方法的具体用法?C++ vvii::size怎么用?C++ vvii::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vvii
的用法示例。
在下文中一共展示了vvii::size方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: bellmann_ford_extended
void bellmann_ford_extended(vvii &e, int source, vi &dist, vb &cyc) {
dist.assign(e.size(), INF);
cyc.assign(e.size(), false); // true when u is in a <0 cycle
dist[source] = 0;
for (int iter = 0; iter < e.size() - 1; ++iter){
bool relax = false;
for (int u = 0; u < e.size(); ++u)
if (dist[u] == INF) continue;
else for (auto &e : e[u])
if(dist[u]+e.second < dist[e.first])
dist[e.first] = dist[u]+e.second, relax = true;
if(!relax) break;
}
bool ch = true;
while (ch) { // keep going untill no more changes
ch = false; // set dist to -INF when in cycle
for (int u = 0; u < e.size(); ++u)
if (dist[u] == INF) continue;
else for (auto &e : e[u])
if (dist[e.first] > dist[u] + e.second
&& !cyc[e.first]) {
dist[e.first] = -INF;
ch = true; //return true for cycle detection only
cyc[e.first] = true;
}
}
}
示例2: dijkstra_multiple_paths
void dijkstra_multiple_paths(vvii& g, int src, vi& dist, vvi& pred) {
// initialize
dist.assign(g.size(), numeric_limits<int>::max());
dist[src] = 0;
pred.assign(g.size(), vector<int>());
set<ii> set = { { 0, src } };
while (!set.empty()) {
// extract min
int u = set.begin()->second;
set.erase(set.begin());
for (auto& e : g[u]) {
int v = e.first;
int w = e.second;
if (dist[u] + w < dist[v]) {
// relax / decrease key
set.erase({ dist[v], v });
dist[v] = dist[u] + w;
pred[v] = { u };
set.insert({ dist[v], v });
} else if(dist[u] + w == dist[v]) {
pred[v].push_back(u);
}
}
}
}
示例3: longest_increasing_subsequence
int longest_increasing_subsequence(vvii &boxes, vi &lis, vi &dad) {
for (int i = 0; i < boxes.size(); i++) {
lis.push_back(1);
dad.push_back(i);
}
int idx = 0;
for (int i = 0; i < boxes.size(); i++) {
for (int j = i - 1; j >= 0; j--) {
if (nests(boxes[i].first, boxes[j].first) and lis[i] < lis[j] + 1) {
lis[i] = lis[j] + 1;
dad[i] = j;
if (lis[i] > lis[idx]) idx = i;
}
}
}
return idx;
}
示例4: showGraph
void showGraph(vvii G){
int n=G.size();
for(int i=0; i<n; i++){
int t=G[i].size();
printf("<%d>:",i);
for(int j=0; j<t; j++){
printf("Vertex:%d, Weight:%d",G[i][j].first,G[i][j].second);
}
printf("\n");
}
}
示例5: dijkstra
void dijkstra(vvii &E, vi &dist, int s) {
int N = E.size();
dist.assign(N, LLINF);
priority_queue<ii, vector<ii>, greater<ii>> pq;
dist[s] = 0LL;
pq.push({0LL, s});
while (!pq.empty()) {
ll d = pq.top().first;
int u = pq.top().second;
pq.pop();
if (d != dist[u]) continue;
for (ii vw : E[u]) {
int v = vw.first;
ll w = vw.second;
if (dist[v] > w + d) {
dist[v] = w + d;
pq.push({dist[v], v});
}
}
}
}