当前位置: 首页>>代码示例>>C++>>正文


C++ vvii类代码示例

本文整理汇总了C++中vvii的典型用法代码示例。如果您正苦于以下问题:C++ vvii类的具体用法?C++ vvii怎么用?C++ vvii使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了vvii类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
				}
	}
}
开发者ID:JohnXinhua,项目名称:TCR-1,代码行数:27,代码来源:bellmannford-extended.cpp

示例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);
            }
        }
    }
}
开发者ID:wenqiangwang,项目名称:algorithms,代码行数:27,代码来源:dijkstra_all_shortest_paths.cpp

示例3: 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;
}
开发者ID:poojagarg,项目名称:Coding,代码行数:35,代码来源:STL_Graph.cpp

示例4: 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;
}
开发者ID:igorcarpanese,项目名称:Competitive-Programming,代码行数:20,代码来源:103.cpp

示例5: 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");
		}	
}
开发者ID:poojagarg,项目名称:Coding,代码行数:11,代码来源:STL_Graph.cpp

示例6: 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});
			}
		}
	}
}
开发者ID:TimonKnigge,项目名称:Competitive-Programming,代码行数:23,代码来源:intercept.cpp

示例7: 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;
}
开发者ID:mehranagh20,项目名称:uvaSolvedPromblems,代码行数:30,代码来源:10510-Cactus.cpp

示例8: main

int main() {
    ios::sync_with_stdio(0);
    int n;
    while(cin >> n && n) {
        graph.assign(n, vii());
        for(int i = 0; i < n - 1; i ++) {
            int a, b; cin >> a >> b;
            a--, b--;
            graph[a].push_back(ii(b, -1)), graph[b].push_back(ii(a, -1));
        }
        ways(n - 1, -1);
        ways(0, -1);
        vi dis(n, -1);
        bfs(0, dis);
        int l = 0, h = 3000, ans = 0;
        while(l <= h) {
            int mid = (l + h) / 2;
            if(check(n - 1, -1, dis, mid)) h = mid - 1, ans = mid;
            else l = mid + 1;
        }
        cout << ans << endl;
    }


    return 0;
}
开发者ID:mehranagh20,项目名称:uvaSolvedPromblems,代码行数:26,代码来源:j.cpp

示例9: main

int main(int argc, char const *argv[])
{
	int n,m,u,v,t,s,r;
	scanf("%d",&t);	
	while(t--){		
		for (int i = 0; i < 4000; ++i)
		{
			dist[i]= 500000;
		}
		memset(visited,0,sizeof(visited));		
		scanf("%d%d",&n,&m);
		adjList.assign(n+1, vii());
		for (int i = 0; i < m; ++i)
		{
			scanf("%d%d%d",&u,&v,&r);
			adjList[u].push_back(ii(v,r));
			adjList[v].push_back(ii(u,r));
		}		
		scanf("%d",&s);
		dijkastra(s);
		for (int i = 1; i <= n; ++i)
		{
			if(i!=s&&dist[i]==500000)
				printf("-1 ");
			else if(i!=s)
				printf("%d ", dist[i]);
		}	
		printf("\n");
	}
	return 0;
}
开发者ID:chandan2495,项目名称:Codechef,代码行数:31,代码来源:dijkastrashortreach.cpp

示例10: 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;
}
开发者ID:mehranagh20,项目名称:uvaSolvedPromblems,代码行数:44,代码来源:10048-Audiophobia.cpp

示例11: 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;
}
开发者ID:ZahraParsaeian,项目名称:Uva_Solved_Problems,代码行数:41,代码来源:10557+XYZZY.cpp

示例12: 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;
}
开发者ID:maryam97,项目名称:ACM,代码行数:40,代码来源:10557+XYZZY.cpp

示例13: 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;
}
开发者ID:ZahraParsaeian,项目名称:Uva_Solved_Problems,代码行数:39,代码来源:10801+Lift+Hopping.cpp

示例14: main

int main() {
    ios::sync_with_stdio(0);
    int tc; cin >> tc;
    while(tc--) {
        int n; cin >> n;
        fc.assign(n, pair<string, int>("", 0));
        for(auto &e: fc) cin >> e.first >> e.first >> e.second;

        n; cin >> n;
        sc.assign(n, pair<string, int>("", 0));
        for(auto &e: sc) cin >> e.first >> e.first >> e.second;

        memo.assign(fc.size() + 10, vii(sc.size() + 10, ii(-1, -1)));
        ii ans = solve(0, 0);
        if(ans.first == inf && ans.second == inf) cout << 0 << " " << 0 << endl;
        else cout << ans.first << " " << ans.second << endl;
    }


    return 0;
}
开发者ID:mehranagh20,项目名称:uvaSolvedPromblems,代码行数:21,代码来源:1172-The-Bridges-of-Kölsberg.cpp

示例15: main

int main() {
    ios::sync_with_stdio(0);
    int tc; cin >> tc;
    while(tc--) {
        scc.clear();
        int n, m; cin >> n >> m;
        AdjList.assign(n, vii());
        for(int i = 0; i < m; i++) {
            int a, b; cin >> a >> b;
            a--, b--;
            if(a != b)
            AdjList[a].push_back(ii(b, 0));
        }
        int V = n;

        dfs_num.assign(V, 0); dfs_low.assign(V, 0); visited.assign(V, 0); node_to_scc_num.assign(V, -1);
        dfsNumberCounter = numSCC = scc_num = 0;
        for (int i = 0; i < V; i++)
            if (dfs_num[i] == 0)
                tarjanSCC(i);

        graph.assign(scc_num, vi());
        for(int i = 0; i < scc.size(); i++) {
            for(int j = 0; j < scc[i].size(); j++) for(auto &e: AdjList[scc[i][j]])
                if(node_to_scc_num[e.first] != i) graph[i].push_back(node_to_scc_num[e.first]);
        }
        memo.assign(scc_num, -1);
        int ans = 0;
        for(int i = 0; i < scc_num; i++) {
            int cur = scc[i].size();
            ans = max(ans, solve(i) + cur);
        }
        cout << ans << endl;

    }


    return 0;
}
开发者ID:mehranagh20,项目名称:uvaSolvedPromblems,代码行数:39,代码来源:11324-The-Largest-Clique.cpp


注:本文中的vvii类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。