haut 1278: Transmit information(倍增floyd)@
来源:互联网 发布:郑州慧牛网络怎么样 编辑:程序博客网 时间:2024/06/07 03:26
题意:求一个图的s到e的长度为k的最短路
解:每次只通过一个节点来疏松原图
#include <iostream>#include <bits/stdc++.h>using namespace std;typedef long long LL;const int N = 1007;const int inf = 999999999;const int mod = 10007;char str[10][10];int n, m, s, e;struct node{ int m[210][210]; node() { for(int i=0; i<210; i++) for(int j=0; j<210; j++) m[i][j]=inf; }};int vis[2200];node quick(node &x,node &y){ node z; for(int k=1; k<=n; k++) for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) z.m[i][j]=min(z.m[i][j],x.m[i][k]+y.m[k][j]); return z;} node mul(node x,int cnt){ node y; for(int i=1; i<=n; i++) y.m[i][i]=0; while(cnt) { if(cnt&1) y=quick(y,x); cnt>>=1; x=quick(x,x); } return y;} int main(){ int t; scanf("%d", &t); while(t--) { int k; scanf("%d %d %d %d", &k, &m, &s, &e); memset(vis,0,sizeof(vis)); node x; int cnt=1; for(int i=0; i<m; i++) { int w, u, v; scanf("%d %d %d", &w, &u, &v); if(!vis[u]) vis[u]=cnt++; if(!vis[v]) vis[v]=cnt++; u=vis[u],v=vis[v]; x.m[u][v]=w,x.m[v][u]=w; } n=cnt-1; x=mul(x,k); printf("%d\n",x.m[vis[s]][vis[e]]); } return 0;}
阅读全文
0 0
- haut 1278: Transmit information(倍增floyd)@
- 【Hautoj 1278 Transmit information】+ dfs
- 倍增Floyd
- Transmit
- POJ 3613 floyd+倍增
- 2165: 大楼 倍增floyd
- bzoj 1706 倍增floyd
- bzoj2165 -- 倍增floyd
- 河南第十届ACM省赛-I-Transmit information
- poj 3613(floyd倍增)
- [POJ3613]Cow Relays && Floyd倍增
- BZOJ 2165 大楼 倍增Floyd
- BZOJ 2165 大楼 倍增Floyd
- [倍增 floyd] BZOJ 2165 大楼
- 跑路 洛谷1613 倍增 floyd
- bzoj 2165: 大楼 倍增floyd
- 洛谷1613 跑路【倍增+floyd】
- 河南省第十届ACM省赛题目:问题 I: Transmit information
- 面向切面变成AOP
- 极其简单的windows环境下的caffe环境搭建:(vs2012+win 64)
- RMQ hdu5289+hdu3183+hdu5726
- 5.15日学习日志
- json与pickle序列化
- haut 1278: Transmit information(倍增floyd)@
- (转)35 个毁掉你代码的不良习惯 !
- 十项全能革新网站开发技术-Zoomla!逐浪CMS2 x3.9.1发布
- mysql常用函数
- C++实验题---填空(求对象的全部数据)
- 【经验记录】pinpoint-web显示不了agent的信息
- Thinkphp的<in>、<notin>和<range>标签的使用和异同
- CentOS7 安装Tomcat
- PHP JSON的BUG