本文整理汇总了C++中graph::resize方法的典型用法代码示例。如果您正苦于以下问题:C++ graph::resize方法的具体用法?C++ graph::resize怎么用?C++ graph::resize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类graph
的用法示例。
在下文中一共展示了graph::resize方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main() {
while(true) {
//scanf("%d\n", &M);
cin >> M;
if(M == 0) break;
//scanf("%s %s\n", name, dest);
cin >> name >> dest;
map<string, int> index;
index[name] = start = index.size() - 1;
index[dest] = end = index.size() - 1;
D(G.size());
G.resize(2);
for(int i = 0; i < M; i++) {
//scanf("%s %s %s\n", name, dest, word);
cin >> name >> dest >> word;
if(index.find(name) == index.end()) {
index[name] = index.size() - 1;
G.resize(G.size()+1);
}
if(index.find(dest) == index.end()) {
index[dest] = index.size() - 1;
G.resize(G.size()+1);
}
int a = index[name], b = index[dest];
//D(a); D(b);
G[a].push_back(ici(b, word[0], word.length()));
G[b].push_back(ici(a, word[0], word.length()));
//D(name); D(dest); D(word);
}
int ans = dijkstraHeap();
if(ans == INF) puts("impossivel");
else printf("%d\n", ans);
G.clear();
}
}
示例2: read_input
void read_input(graph &adj){
int n, m;
cin >> n >> m;
adj.resize(n);
for(int i = 0; i < m; i++){
vertex u, v;
cin >> u.id >> v.id;
adj[u.id].push_back(v);
adj[v.id].push_back(u);
adj[u.id].back().it = adj[v.id].end();
--adj[u.id].back().it;
adj[v.id].back().it = adj[u.id].end();
--adj[v.id].back().it;
}
}
示例3: construct_graph
void construct_graph(vector<string>& words) {
for (int i = 0; i < words.size(); i++) {
insert(words[i], i);
}
g.resize(words.size());
height.resize(words.size(), 1);
vector<string> neighbours;
pair<string, int> elem;
for (int i = 0; i < words.size(); i++) {
all_combos(words[i], neighbours);
for (int j = 0; j < neighbours.size(); j++) {
elem = find(neighbours[j]);
if (elem.second > 0) {
insert(i, elem.second);
}
}
}
}
示例4: main
int main(void) {
int i, x, y, l;
cin >> n >> k >> sh >> sc;
g.resize(n);
deg.resize(n);
nbdesc.resize(n, 1);
len.resize(n - 1);
occur.resize(n - 1);
ordered.resize(n - 1);
for (i = 0; i < n - 1; ++i) {
cin >> x >> y >> l;
--x;
--y;
len[i] = l;
g[x].push_back(make_pair(y, i));
g[y].push_back(make_pair(x, i));
}
effeuille();
compute();
return 0;
}
示例5: reset
void reset() {
g.clear();
g.resize(size);
}
示例6: add_vertex
// Add a vertex to g and return its id
// Complexity: O( 1 )
inline vertex_id add_vertex( graph& g )
{
vertex_id v = g.size();
g.resize( v + 1 );
return v;
}