标签:
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 38549 | Accepted: 11158 |
Description
Input
Output
Sample Input
1 4 10000 3 2 2 8000 3 5000 1000 2 1 4 200 3000 2 1 4 200 50 2 0
Sample Output
5250
Source
1 #include<stdio.h> 2 #include<string.h> 3 #include<algorithm> 4 using namespace std; 5 const int inf = 0x3f3f3f3f , MAX = 200 ; 6 int map[MAX][MAX] , p[MAX] , d[MAX] , rank[MAX] ; 7 bool vis[MAX] ; 8 int m , n , x ; 9 int t , v ; 10 11 void dijkstra (int l , int r) 12 { 13 memset (vis , 0 , sizeof(vis)) ; 14 for (int i = 1 ; i <= n ; i++) { 15 if (rank[i] < l || rank[i] > r) 16 vis[i] = 1 ; 17 d[i] = inf ; 18 } 19 d[1] = 0 ; 20 for (int i = 1 ; i <= n ; i++) { 21 int minc = inf , k ; 22 for (int j = 1 ; j <= n ; j++) { 23 if ( !vis[j] && d[j] < minc) { 24 minc = d[j] ; 25 k = j ; 26 } 27 } 28 vis[k] = 1 ; 29 for (int j = 1 ; j <= n ; j++) { 30 if (!vis[j] && d[j] > d[k] + map[k][j]) 31 d[j] = d[k] + map[k][j] ; 32 } 33 } 34 } 35 int main () 36 { 37 // freopen ("a.txt" , "r" , stdin) ; 38 int ans ; 39 while (~ scanf ("%d%d" , &m , &n)) { 40 for (int i = 0 ; i <= n ; i++) 41 for (int j = 0 ; j <= n ; j++) 42 map[i][j] = inf ; 43 for (int i = 1 ; i <= n ; i++) { 44 scanf ("%d%d%d" , &p[i] , &rank[i] , &x) ; 45 while (x--) { 46 scanf ("%d%d" , &t , &v) ; 47 map[i][t] = v ; 48 } 49 } 50 ans = inf ; 51 for (int i = rank[1] - m ; i <= rank[1] ; i++) { 52 dijkstra (i , i + m) ; 53 for (int j = 1 ; j <= n ; j++) 54 ans = min (ans , p[j] + d[j]) ; 55 } 56 printf ("%d\n" , ans) ; 57 } 58 return 0 ; 59 }
标签:
原文地址:http://www.cnblogs.com/get-an-AC-everyday/p/4308885.html