C++实现floyd-warshall算法
来源:互联网 发布:php企业网站模板 编辑:程序博客网 时间:2024/06/07 06:59
#include<iostream>#include<cctype>#include<sstream>#include<string>#include<algorithm>#include<map>#include<cstring>#include<cstdio>#include<iomanip>#include<vector>#include<queue>using namespace std;const int INF = 100000000;void ch_status(vector<vector<int> > & W, int nNodes) {//DP, just like bellmanford.for (int k = 0; k < nNodes; ++k) {for (int i = 0; i < nNodes; ++i) {for (int j = 0; j < nNodes; ++j) {if (W[i][j] > W[i][k] + W[k][j]) {W[i][j] = W[i][k] + W[k][j];}}}}}void display(const vector<vector<int> > & W) {int nNodes = W.size();for (int i = 0; i < nNodes; ++i) {for (int j = 0; j < nNodes; ++j) {cout << " " << setw(3) << W[i][j];}cout << endl;}}int main(void) {cout << "Floyd-Warshall algorithm for Directed Acyclic Graph: " << endl;while (true) {int nNodes;cout << "Number of Nodes: ";cin >> nNodes;vector<vector<int> > Wgt(nNodes, vector<int>(nNodes, INF));for (int i = 0; i < nNodes; ++i)Wgt[i][i] = 0;int nEdges;cout << "Number of Edges: ";cin >> nEdges;cout << "Src Dest Dist(< " << INF << "): " << endl;for (int i = 0; i < nEdges; ++i) {int src, dest, dist;cout << "[" << i << "]: ";cin >> src >> dest >> dist;Wgt[src][dest] = dist;}for (int i = 0; i < nNodes; ++i) {for (int j = 0; j < nNodes; ++j) {if (Wgt[i][j] != INF)cout << " " << setw(3) << Wgt[i][j];elsecout << " " << "INF";}cout << endl;}//O(n^3), amazing, the fastest ever known!!while (true) {ch_status(Wgt, nNodes);display(Wgt);system("pause");}}return 0;}
0 0
- Floyd-Warshall算法实现类
- Floyd-Warshall算法实现类
- C++实现floyd-warshall算法
- Floyd-Warshall 算法 C++实现
- Floyd-Warshall算法(Floyd-Warshall algorithm)
- Floyd-Warshall 算法
- Floyd-Warshall算法
- poj1125 Floyd-Warshall算法
- Floyd-Warshall算法详解
- Floyd-Warshall算法
- Floyd-Warshall算法
- Floyd-Warshall算法
- Floyd-Warshall算法
- 复习Floyd-Warshall算法
- Floyd-Warshall算法详解
- ACM_Floyd-Warshall (Floyd) 算法
- Floyd-Warshall算法
- floyd-warshall算法
- 自己的QT下载与配置
- struts2学习笔记(1)---JSP页面向Action类传递参数
- 一起学编程(3--组织与表达)
- 自定义一个异常类模板代码实例
- leetcode 106 【中序,后序建树】
- C++实现floyd-warshall算法
- 在CSDN的第一篇博客。
- 最长公共子串(Longest Common Substring)
- IntelliJ 14 maven3.3.3 -Dmaven.multiModuleProjectDirectory system propery is not set. Check $M2_HOME
- SDUT 2132 数据结构实验之栈二:一般算术表达式转换成后缀式
- Linux网络编程必看书籍推荐 网络学习的捷径,正在学习中
- 远程问题解决方案(连接到** 的凭据无法工作,请输入新凭据)
- 【20150525-20150529】sql、oracle方向总结(truncate、execute、exception、系统视图与表属性)
- chapter11test2