标签:graph str can auth silver alt transport ref none
专题四 最短路练习
√ POJ 2387 Til the Cows Come Home
POJ 2253 Frogger
POJ 1797 Heavy Transportation
POJ 3268 Silver Cow Party
POJ 1860 Currency Exchange
POJ 3259 Wormholes
POJ 1502 MPI Maelstrom
POJ 3660 Cow Contest
POJ 2240 Arbitrage
POJ 1511 Invitation Cards
POJ 3159 Candies
POJ 2502 Subway
POJ 1062 昂贵的聘礼
POJ 1847 Tram
LightOJ 1074 Extended Traffic
HDU 4725 The Shortest Path in Nya Graph
HDU 3416 Marriage Match IV
HDU 4370 0 or 1
POJ 3169 Layout
// poj 2387
1 /* 2 * @Promlem: 3 * @Time Limit: ms 4 * @Memory Limit: k 5 * @Author: pupil-XJ 6 * @Date: 2019-10-25 08:14:08 7 * @LastEditTime: 2019-10-25 08:25:39 8 */ 9 #include<cstdio> 10 #include<cstring> 11 #include<cmath> 12 #include<iostream> 13 #include<string> 14 #include<algorithm> 15 #include<vector> 16 #include<queue> 17 #include<stack> 18 #include<set> 19 #include<map> 20 #define rep(i, n) for(int i=0;i!=n;++i) 21 #define per(i, n) for(int i=n-1;i>=0;--i) 22 #define Rep(i, sta, n) for(int i=sta;i!=n;++i) 23 #define rep1(i, n) for(int i=1;i<=n;++i) 24 #define per1(i, n) for(int i=n;i>=1;--i) 25 #define Rep1(i, sta, n) for(int i=sta;i<=n;++i) 26 #define L k<<1 27 #define R k<<1|1 28 #define mid (tree[k].l+tree[k].r)>>1 29 using namespace std; 30 const int INF = 0x3f3f3f3f; 31 typedef long long ll; 32 33 inline int read() { 34 char c=getchar();int x=0,f=1; 35 while(c<‘0‘||c>‘9‘){if(c==‘-‘)f=-1;c=getchar();} 36 while(c>=‘0‘&&c<=‘9‘){x=x*10+c-‘0‘;c=getchar();} 37 return x*f; 38 } 39 // ----------------------------------------------------- 40 const int MAXN = 1000+5; 41 int T, n; 42 int G[MAXN][MAXN]; 43 44 int vis[MAXN], dis[MAXN]; 45 46 int dij() { 47 rep1(i, n) { 48 dis[i] = G[i][1]; 49 vis[i] = 0; 50 } 51 vis[1] = 1; 52 rep(i, n-1) { 53 int minn = INF; 54 int t; 55 rep1(j, n) { 56 if(!vis[j] && dis[j] < minn) { 57 minn = dis[j]; 58 t = j; 59 } 60 } 61 vis[t] = 1; 62 rep1(j, n) { 63 if(!vis[j] && dis[j] > dis[t] + G[t][j]) { 64 dis[j] = dis[t] + G[t][j]; 65 } 66 } 67 } 68 return dis[n]; 69 } 70 71 int main() { 72 ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); 73 int s, e, v; 74 while(cin >> T >> n) { 75 rep1(i, n) rep1(j, n) G[i][j] = INF; 76 rep(i, T) { 77 cin >> s >> e >> v; 78 if(v < G[s][e]) G[s][e] = G[e][s] = v; 79 } 80 cout << dij() << "\n"; 81 } 82 return 0; 83 }
标签:graph str can auth silver alt transport ref none
原文地址:https://www.cnblogs.com/pupil-xj/p/11736071.html