日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

POJ 3615 floyd 求任意起点终点的最短路

發布時間:2025/5/22 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 POJ 3615 floyd 求任意起点终点的最短路 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

http://poj.org/problem?id=3615

題意:求起點到終點的最短路,不存在則輸出-1.這題居然tle兩次,把floyd放在外面就行了。

View Code // I'm lanjiangzhou //C #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include <math.h> #include <time.h> //C++ #include <iostream> #include <algorithm> #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <cctype> #include <stack> #include <string> #include <list> #include <queue> #include <map> #include <vector> #include <deque> #include <set> using namespace std;//*************************OUTPUT************************* #ifdef WIN32 #define INT64 "%I64d" #define UINT64 "%I64u" #else #define INT64 "%lld" #define UINT64 "%llu" #endif//**************************CONSTANT*********************** #define INF 0x3f3f3f3f #define eps 1e-8 #define PI acos(-1.) #define PI2 asin (1.); typedef long long LL; //typedef __int64 LL; //codeforces typedef unsigned int ui; typedef unsigned long long ui64; #define MP make_pair typedef vector<int> VI; typedef pair<int, int> PII; #define pb push_back #define mp make_pair//***************************SENTENCE************************ #define CL(a,b) memset (a, b, sizeof (a)) #define sqr(a,b) sqrt ((double)(a)*(a) + (double)(b)*(b)) #define sqr3(a,b,c) sqrt((double)(a)*(a) + (double)(b)*(b) + (double)(c)*(c))//****************************FUNCTION************************ template <typename T> double DIS(T va, T vb) { return sqr(va.x - vb.x, va.y - vb.y); } template <class T> inline T INTEGER_LEN(T v) { int len = 1; while (v /= 10) ++len; return len; } template <typename T> inline T square(T va, T vb) { return va * va + vb * vb; }// aply for the memory of the stack //#pragma comment (linker, "/STACK:1024000000,1024000000") //endconst int maxn =1010; int edges[maxn][maxn]; int n,m,t; int u,v,w; int maxx(int a,int b){return a>b?a:b; } int minn(int a,int b){return a>b?b:a; }void floyd(){for(int k=1;k<=n;k++){for(int i=1;i<=n;i++){for(int j=1;j<=n;j++){edges[i][j]=minn(edges[i][j],maxx(edges[i][k],edges[k][j]));}}} }int main(){while(scanf("%d%d%d",&n,&m,&t)!=EOF){for(int i=1;i<=n;i++){for(int j=1;j<=n;j++){edges[i][j]=INF;}edges[i][i]=0;}for(int i=1;i<=m;i++){scanf("%d%d%d",&u,&v,&w);edges[u][v]=w;}int start,end;floyd();//放在外面,里面超時for(int i=1;i<=t;i++){scanf("%d%d",&start,&end);if(edges[start][end]==INF){printf("-1\n");}else printf("%d\n",edges[start][end]);}}//floyd();return 0; }

?

轉載于:https://www.cnblogs.com/lanjiangzhou/archive/2013/04/02/2995962.html

總結

以上是生活随笔為你收集整理的POJ 3615 floyd 求任意起点终点的最短路的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。