find the mincost route
来源:互联网 发布:weiphp绑定域名 编辑:程序博客网 时间:2024/06/01 09:35
find the mincost route
Time Limit: 1000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2927 Accepted Submission(s): 1180
接下来的M行里,每行包括3个整数a,b,c.代表a和b之间有一条通路,并且需要花费c元(c <= 100)。
3 31 2 12 3 11 3 13 31 2 11 2 32 3 1
3It's impossible.
Floyd算法 求最小环
#include<iostream>
#include<queue>
using namespace std;
struct ssss
{
int n,d,sum;
friend bool operator <(ssss a,ssss b)
{
return a.sum>b.sum;
}
}s,ss;
int main()
{
int n,m;
const int Mod=1e8+7;
int Map[111][111],fly[111][111];
bool flag[111][111];
while(cin>>n>>m)
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
Map[i][j]=Mod,fly[i][j]=Mod;
}
while(m--)
{
int a,b,c;
cin>>a>>b>>c;
if(c<Map[a][b]) Map[a][b]=c,Map[b][a]=c,fly[a][b]=c,fly[b][a]=c;
}
int sum=Mod;
//cout<<sum<<endl;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
for(int k=1;k<=n;k++)
{
sum=min(sum,fly[j][k]+Map[i][j]+Map[i][k]); //更新以i为顶点的环的值
}
}
for(int j=1;j<=n;j++)
{
for(int k=1;k<=n;k++)
{
if(j!=k)
fly[j][k]=min(fly[j][i]+fly[i][k],fly[j][k]); //Floyd
}
}
}
if(sum<Mod) cout<<sum<<endl;
else cout<<"It's impossible."<<endl;
}
return 0;
}
- find the mincost route
- find the mincost route
- find the mincost route
- find the mincost route
- find the mincost route
- find the mincost route
- find the mincost route
- HDU1599 find the mincost route
- hdu1599 find the mincost route
- hdu1599 find the mincost route
- hdu1599 find the mincost route
- Hdoj find the mincost route
- find the mincost route hdoj1599
- HDU1599:find the mincost route
- HDU_1599 find the mincost route
- find the mincost route HDU
- hdu1599 find the mincost route
- [hdu1599]find the mincost route
- 剑指offer名企面试编程题:第一个只出现一次的字符
- 黑马程序员 ——OC基础知识
- 基于PCA和SVM的人脸识别系统-error修改
- IOS学习之IOS沙盒(sandbox)机制和文件操作(一)
- hpu 2647 拓扑排序 + vector不定长数组的使用方法
- find the mincost route
- 群论的角度解释无监督深度学习
- A\B?
- IOS开发中经常遇到的问题
- Java虚拟机解析篇之---内存模型
- CSS入门
- Ubuntu 12.04.1 LTS下编译live555
- 数组越界问题——危险
- spring MVC interceptor post遇到问题