1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
#include <iostream> #include <set> #include <algorithm> #include <string.h> #include<queue> #include<stack> #define ll long long using namespace std; int n, m; #define inf 0x3f3f3f3f int maze[1000][1000]; void () { for (int k = 1; k <= m;k++) { for (int i = 1; i <= m;i++) { for (int j = 1; j <= m;j++) { maze[i][j] = min(maze[i][j], maze[i][k] + maze[k][j]); } } } } int main() { scanf("%d%d", &m, &n); memset(maze,inf,sizeof maze); for (int i = 1; i <= n;i++) { int a, b, c; scanf("%d%d%d", &a, &b, &c); maze[a][b] = c; maze[b][a] = c; } int s, t; scanf("%d%d", &s, &t); floy(); if(s==t) printf("0n"); else printf("%dn", maze[s][t]); }
|
近期评论