本文整理汇总了C++中vvii::resize方法的典型用法代码示例。如果您正苦于以下问题:C++ vvii::resize方法的具体用法?C++ vvii::resize怎么用?C++ vvii::resize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vvii
的用法示例。
在下文中一共展示了vvii::resize方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: buildGraph
vvii buildGraph(){
int n;
printf("no of vertices:");
scanf("%d",&n);//no of vertices
FILE* fp=fopen("weightedGraph.txt","r");
vvii G(100);
G.resize(n);
/*printf("<G size:%d>",G.size());
for(int l=0; l<n; l++)
printf("<%d>",G[l].size());*/
int i,a,w;
do{
fscanf(fp,"%d",&i);
//printf("<%d>",i);
if(i>=n) {printf("breaking because %d",i);break;}
char c='a';
while(c!='\n'){
fscanf(fp,"%d",&a);
fscanf(fp,"%d",&w);
ii p;
p.first=a; p.second=w;
G[i].push_back(p);
fscanf(fp,"%c",&c);
//printf("%d %d %c",p.first,p.second,c);
//debug();
}
}while(i!=n-1);
return G;
}
示例2: main
int main() {
int tc;
cin >> tc;
while (tc--) {
int n, m;
cin >> n >> m;
AdjList.clear(); AdjList.resize(n);
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
AdjList[a].push_back(ii(b, 0));
}
bool cac = true;
int numScc = 0;
dfs_num.clear(); dfs_num.resize(n, UNVISITED);
dfs_parent.clear(); dfs_parent.resize(n, 0);
for(int i = 0; i < n; i++) {
if(dfs_num[i] == UNVISITED) {
numScc++;
if(graphCheck(i)) {
cac = false;
break;
}
}
}
if(cac && numScc == 1) cout << "YES\n";
else cout << "NO\n";
}
return 0;
}
示例3: main
int main() {
ios::sync_with_stdio(0);
int n, m, q, tc = 0;
while(cin >> n >> m >> q && (m || n || q)) {
if(tc++) cout << endl;
buildUfds(n);
edges.clear();
for(int i = 0; i < m; i++) {
int a, b, d; cin >> a >> b >> d;
edges.push_back(make_pair(d, make_pair(a - 1, b - 1)));
}
sort(edges.begin(), edges.end());
graph.clear(); graph.resize(n);
kruskal();
cout << "Case #" << tc << endl;
vvi memo(n, vi(n, -1));
for(int i = 0; i < q; i++) {
int a, b; cin >> a >> b;
a--; b--;
if(memo[a][b] != -1) {
if(memo[a][b] == -2) cout << "no path\n";
else cout << memo[a][b] << endl;
}
else if(memo[b][a] != -1) {
if(memo[b][a] == -2) cout << "no path\n";
else cout << memo[b][a] << endl;
}
else {
des = b; ans = -inf;
vis.clear(); vis.resize(n, 0);
dfs(a);
if (ans != -inf) {
cout << ans << endl;
memo[a][b] = memo[b][a] = ans;
}
else {
cout << "no path\n";
memo[a][b] = memo[b][a] = -2;
}
}
}
}
return 0;
}
示例4: main
int main(){
ios::sync_with_stdio(0);
while(cin >> n && (n != -1)) {
vec.clear();
vec.resize(n);
int enrgy, b, num;
for (int i = 0; i < n; ++i) {
cin >> enrgy >> num;
for (int j = 0; j < num; ++j) {
cin >> b;
vec[i].push_back(ii(enrgy, b - 1));
}
}
blmnfrd();
vis.clear(); vis.resize(n , 0);
dfs(0);
vi vis1 = vis;
if(dist[n - 1] > 0) cout << "winnable" << endl;
else {
bool happen = false;
for (int i = 0; i < n && !happen; ++i)
for (auto j : vec[i])
if (dist[j.second] < dist[i] + j.first && dist[i] + j.first > 0) {
vis.clear(); vis.resize(n,0);
dfs(i);
if (vis[n - 1] && vis1[i]) {
happen = true;
break;
}
}
//if(chk()) cout << "winnable" << endl;
if (happen) cout << "winnable" << endl;
else cout << "hopeless\n";
}
}
return 0;
}
示例5: main
int main(){
ios::sync_with_stdio(0);
int door,w,a;
while(cin >> n && (n!=-1)){
adjlist.clear();
adjlist.resize(n);
vis.clear(); vis.resize(n,0);
for (int i = 0; i < n; ++i) {
cin >> w >> door;
while(door--){
cin >> a;
adjlist[i].push_back(ii(a-1,w));
}
}
bellmanFord();
if(dist[n-1] > 0) cout << "winnable\n";
else{
bool haspos = false;
for (int i = 0; i < n && !haspos; ++i) {
for(auto & e: adjlist[i]){
if(dist[i] + e.second > 0 && dist[e.first] < dist[i] + e.second){
vis.clear(); vis.resize(n,0);
dfs(i);
if(vis[n-1] ){
haspos = true;
break;
}
}
}
}
if(haspos) cout << "winnable\n";
else cout << "hopeless\n";
}
}
return 0;
}
示例6: main
int main(){
ios::sync_with_stdio(0);
while (cin >> n >> k){
vi speed(n);
vec.clear(); vec.resize(100);
for (int i = 0; i < n; ++i)
cin >> speed[i];
string a , chert;
getline(cin , chert);
map <int , int > m;
for ( int i = 0; i < n; i++) {
getline(cin, a);
stringstream str(a);
int num;
vi tmp;
while (str >> num)
tmp.push_back(num), m[num] = 1;
for (int ii = 0; ii < tmp.size(); ii++) {
for (int j = ii + 1; j < tmp.size() ; j++) {
vec[tmp[ii]].push_back(make_pair(speed[i] * (tmp[j] - tmp[ii]), tmp[j]));
vec[tmp[j]].push_back(make_pair(speed[i] * (tmp[j] - tmp[ii]), tmp[ii]));
}
}
}
int ans = dijkstra();
if(ans != inf) {
if (k != 0)
ans -= 60;
cout << ans << endl;
}
else cout << "IMPOSSIBLE\n";
}
return 0;
}
示例7: main
int main() {
// freopen("in.txt", "r", stdin);
scanf("%d %d", &n, &m);
a.resize(n + 1);
for (int i = 0; i < m; i++) {
int u, v, c;
scanf("%d %d %d", &u, &v, &c);
a[u].push_back(ii(v, c));
}
clr(vis, false);
ll dist[n + 1];
for (int i = 1; i <= n; i++)
dist[i] = LONG_LONG_MIN;
int ss, f;
cin >> ss >> f;
tls(ss);
// for (int i = 1; i <= n; i++)
// if (!vis[i])
// tls(i);
reverse(all(s));
dist[ss] = 0;
for (int i = 0; i < sz(s); i++) {
int u = s[i];
for (int j = 0; j < sz(a[u]); j++) {
int v = a[u][j].first;
if (dist[u] == LONG_LONG_MIN)
continue;
dist[v] = max(dist[v], dist[u] + (long long) a[u][j].second);
}
}
if (dist[f] == LONG_LONG_MIN)
printf("No solution\n");
else
printf("%lld\n", dist[f]);
return 0;
}