标签:mon == stream ane 结束 style 复试上机 memset i++
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 43967 Accepted Submission(s): 12599
#include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <iostream> #include <algorithm> #include <iostream> #include<cstdio> #include<string> #include<cstring> #include <stdio.h> #include <queue> #include <string.h> #include <vector> #include <map> #define ME(x , y) memset(x , y , sizeof(x)) #define SF(n) scanf("%d" , &n) #define rep(i , n) for(int i = 0 ; i < n ; i ++) #define INF 0x3f3f3f3f #define mod 1024 using namespace std; typedef long long ll ; int n , m ; int b , e ; int ma[1009][1009]; int dis[1009]; int val[1009][1009]; int val1[1009]; int vis[1009]; void Dijia(int r) { for(int i = 1 ; i <= n ; i++) { dis[i] = ma[r][i]; val1[i] = val[r][i]; } vis[r] = 1 ; for(int i = 1 ; i < n ; i++) { int min1 = INF; int min2 = INF; int pos ; for(int j = 1 ; j <= n ; j++) { if(!vis[j]) { if(min1 > dis[j]) { min1 = dis[j]; min2 = val1[j]; pos = j ; } else if(min1 == dis[j]) { min2 = min(min2 , val1[j]); pos = j ; } } } vis[pos] = 1 ; for(int j = 1 ; j <= n ; j++) { if(dis[j] > dis[pos] + ma[pos][j]) { dis[j] = dis[pos] + ma[pos][j]; val1[j] = val1[pos] + val[pos][j]; } else if(dis[j] == dis[pos] + ma[pos][j]) { val1[j] = min(val1[j] , val1[pos] + val[pos][j]); } } } } int main() { while(~scanf("%d%d" , &n , &m) && (n || m)) { memset(ma , INF , sizeof(ma)); memset(val , INF , sizeof(val)); memset(vis , 0 , sizeof(vis)); for(int i = 1 ; i <= m ; i++) { int f , t , w , v ; scanf("%d%d%d%d" , &f , &t , &w , &v); if(ma[f][t] > w)//这里要注意可能出现同一条路线,但距离和价值都不同,需要对应起来 { ma[f][t] = ma[t][f] = w; val[f][t] = val[t][f] = v; } else if(ma[f][t] == w) { val[f][t] = val[t][f] = min(val[f][t] , v); } } scanf("%d%d" , &b , &e); Dijia(b); printf("%d %d\n" , dis[e] , val1[e]); } return 0 ; }
标签:mon == stream ane 结束 style 复试上机 memset i++
原文地址:https://www.cnblogs.com/nonames/p/11367977.html