SPFA随手写,容易理解的
来源:互联网 发布:mac系统下怎么截图 编辑:程序博客网 时间:2024/05/11 13:49
对应的图是
// spfa.cpp : Defines the entry point for the console application.
//#include "stdafx.h"
#include <iostream>
#include <queue>
#include<vector>
using namespace std;
int graph[8][8];
#include<string>
bool visited[8];
int dis[8];
int pre[8];
void spfa(int graph[][8],int s,int e,int n)
{
memset(visited,false,sizeof(visited));
memset(dis,127,sizeof(dis));
memset(pre,0,sizeof(pre));
queue<int> q;
q.push(s);
visited[s]=true;
dis[s]=0;
while(!q.empty())
{
int top=q.front();
q.pop();
visited[top]=false;
for (int i=0;i<n;i++)
{
if (graph[top][i]!=0)
{
if (dis[i]>dis[top]+graph[top][i])
{
dis[i]=dis[top]+graph[top][i];
if(!visited[i])
{
visited[i]=true;
q.push(i);
}
}
}
}
}
for (int i=0;i<n;i++)
{
cout<<i<<" "<<dis[i]<<endl;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
memset(graph,0,sizeof(graph));
graph[0][1]=24;
graph[0][2]=8;
graph[0][3]=15;
graph[1][4]=6;
graph[2][4]=7;
graph[2][5]=3;
graph[3][6]=4;
graph[4][6]=9;
graph[5][6]=3;
graph[5][4]=2;
graph[6][1]=3;
spfa(graph,0,6,7);
return 0;
}
0 0
- SPFA随手写,容易理解的
- 国际:写一手容易理解的代码是否很重要?
- c++链表(随手写的)
- 随手写的flex画板
- 随手写的代码记录
- react js 随手写的
- 随手写的Webview使用
- 容易理解的傅里叶变换
- 随手写
- 随手记一记学Perl 时容易搞混的地方
- 保存我随手写的C++代码
- 随手写的一张移动端页面
- 自己写的随手记事程序
- 复制文件夹及其子文件夹的内容(还是自己写的容易理解)
- spfa算法的初步理解
- com快速入门---自我感觉 对com写得比较容易理解的一个frame类的文章
- 随手写的一些异想天开的程序(1)
- 写JAVA容易患的错误
- PAT1076 Forwards on Weibo
- 关于Struts2.xml的配置
- 关于cisco网络设备访问控制列表ACL中IN、OUT的理解
- leetcode--Palindrome Number
- xwiki6.X版本升级日志
- SPFA随手写,容易理解的
- Android Launcher全面剖析
- 使用 VisualVM 进行性能分析及调优
- poj2886
- Fix【推荐】
- 【Best Coder】Baby Ming and Weight lifting(水)
- poj2255——Tree Recovery(应用二叉树)
- 29 同位词的统计
- 包管理软件