2017.11.8. Floyed求最小环
来源:互联网 发布:png格式打开软件 编辑:程序博客网 时间:2024/06/07 14:48
Floyed求最小环
适合题型:
1.求最小环
样题: HDU1599
std.cpp:
#include<iostream>#include<iomanip>#include<cstdio>#include<cstdlib>#include<string>#include<cstring>#include<algorithm>#include<cmath>#include<queue>#include<vector>using namespace std;inline int read(){ int x=0,w=1;char ch=0; while(ch< '0'||'9' <ch){if(ch=='-')w=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();} return x*w;}typedef long long ll;inline ll red(){ ll x=0,w=1;char ch=0; while(ch< '0'||'9' <ch){if(ch=='-')w=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();} return x*w;}#define maxx 2000inline char *get_str(char *str){ fgets(str,maxx,stdin); if(str[strlen(str)-1]=='\n') str[strlen(str)-1]='\0'; return str;}int n,m,u,v,val;int f[105][105],dis[105][105];int main(){ while(~scanf("%d%d",&n,&m)) { for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) f[i][j]=1e8,dis[i][j]=1e8; for(int i=1;i<=m;i++) { u=read();v=read();val=read(); f[u][v]=f[v][u]=dis[u][v]=dis[v][u]=min(val,f[u][v]); } int ans=1e8; for(int k=1;k<=n;k++) { for(int i=1;i<k;i++) for(int j=i+1;j<k;j++) ans=min(ans,dis[i][j]+f[i][k]+f[k][j]); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]); } if(ans==1e8)cout<<"It's impossible."<<endl; else cout<<ans<<endl; } return 0;}
阅读全文
0 0
- 2017.11.8. Floyed求最小环
- floyed求最小环
- 【floyed求最小环】观光旅游
- 心灵的抚慰 floyed求最小环
- 求最小环 floyed 与 dijkstra
- URAL1004---Sightseeing trip (Floyed求最小环)
- 观光旅游(floyed最小环)
- 洛谷P2738 [USACO4.1]篱笆回路Fence Loops(Floyed求最小环)
- Codevs 2611 观光旅游(floyed最小环)
- floyd求最小环
- floyd求最小环
- floyd求最小环
- floyd求最小环
- FLOYD 求最小环
- floyd求最小环
- floyd求最小环
- Floyd求最小环
- floyd求最小环
- 上传图片
- Spark杂记
- hive sql 总结
- org.apache.solr.client.solrj.impl.HttpSolrServer$RemoteSolrException: Document contains multiple val
- Linux内核分析
- 2017.11.8. Floyed求最小环
- 关于De-pCode在线工具失效的问题
- Linux命令行总结
- react native onPress响应方法是否加bind(this)
- js中怎样获取当前的时间戳
- Spring--《Spring实战》第6章ValidationMessages.properties使用问题
- iOS 用代码修改图片颜色
- SSM学生管理系统SpringMVC+MyBatis
- Jlink接口的Jtag和SWD接口定义