<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12
      書山有徑勤為路>>>>>>>>

      <<<<<<<<學海無涯苦作舟!

      spfa算法解決POJ 2387

      Description

      Bessie is out in the field and wants to get back to the barn to get as much sleep as possible before Farmer John wakes
      her for the morning milking. Bessie needs her beauty sleep, so she wants to get back as quickly as possible. 

      Farmer John's field has N (2 <= N <= 1000) landmarks in it, uniquely numbered 1..N. Landmark 1 is the barn; the apple
      tree grove in which Bessie stands all day is landmark N. Cows travel in the field using T (1 <= T <= 2000) bidirectional
      cow-trails of various lengths between the landmarks. Bessie is not confident of her navigation ability, so she always stays
      on a trail from its start to its end once she starts it. 

      Given the trails between the landmarks, determine the minimum distance Bessie must walk to get back to the barn. It is
      guaranteed that some such route exists.

      Input

      * Line 1: Two integers: T and N 

      * Lines 2..T+1: Each line describes a trail as three space-separated integers. The first two integers are the landmarks
      between which the trail travels. The third integer is the length of the trail, range 1..100.

      Output

      * Line 1: A single integer, the minimum distance that Bessie must travel to get from landmark N to landmark 1.

      Sample Input

      5 5
      1 2 20
      2 3 30
      3 4 20
      4 5 20
      1 5 100

      Sample Output

      90
      
      
      
      
      spfa算法的輸入是很講究的,之所以這樣
      我想是方便后面用queue來存儲和取出。
      明白了輸入是怎么一回事,搞清spfa的過程
      就不是問題了。我在下面的代碼給出了我
      研究過程的代碼,肯定會對大家有幫助的。
      View Code
      #include "iostream"
      #include "queue"
      using namespace std;
      #define N 10000
      #define Max 0x7FFFFFFF
      typedef struct Node{
          int u, value, next;
      }node;
      node e[N];
      int n, m;
      int dis[N], p[N];
      bool vis[N];
      void init(){
          memset(p, -1, sizeof(p));
          memset(vis, false, sizeof(vis));
          fill(dis, dis+N, Max);
          int temp = 0; 
          int a, b, c;
          for(int i=0; i<n; i++){
              cin>>a>>b>>c;
              e[temp].u = b;
              e[temp].value = c;
              e[temp].next = p[a];
              p[a] = temp;
              temp ++;
              e[temp].u = a;
              e[temp].value = c;
              e[temp].next = p[b];
              p[b] = temp;
              temp++;
          }
      }
      void spfa(int s){
          dis[s] = 0;
          queue<int> q;
          q.push(s);
          while(!q.empty()){
              int t = q.front();
              q.pop();
              vis[t] = false;
              int j;
              for(j=p[t]; j!=-1; j=e[j].next){
                  int w=e[j].value;
                  int temp = e[j].u;
                  if(w+dis[t] < dis[temp]){
                      dis[temp] = w+dis[t];
                      if(!vis[temp]){
                          vis[temp] = true;
                          q.push(temp);
                      }
                  }
              }
          }
      }
      int main()
      {
          while(cin>>n>>m && (n+m))
          {
              init();
              spfa(1);
              cout<<dis[m]<<endl;
          }
          return 0;
      }
      
      

       

       

      posted on 2011-10-07 10:20  More study needed.  閱讀(232)  評論(0)    收藏  舉報

      導航

      書山有徑勤為路>>>>>>>>

      <<<<<<<<學海無涯苦作舟!

      主站蜘蛛池模板: 日韩人妻无码一区二区三区99| 人妻中文字幕不卡精品| 国产成人午夜在线视频极速观看| 欧美日韩精品一区二区视频| 国产精品久久欧美久久一区| 亚洲天堂成人一区二区三区| 国产精品午夜无码AV天美传媒| 国产日韩精品欧美一区灰| 97久久人人超碰国产精品| 久久亚洲精品亚洲人av| 都兰县| 国产亚洲欧洲AⅤ综合一区| 国产精品福利自产拍久久| 亚洲国产精品成人综合久| 亚洲精品区午夜亚洲精品区 | 伊人蕉影院久亚洲高清| 精品亚洲精品日韩精品| 成人午夜av在线播放| 日本牲交大片免费观看| 国产美女直播亚洲一区色| 亚洲精品在线二区三区| 阳信县| 精品国产精品午夜福利| 日韩精品18禁一区二区| 精品无人码麻豆乱码1区2区| 深夜福利成人免费在线观看| 久久精品国产99麻豆蜜月| 国产成人精品午夜二三区| 国产日韩av二区三区| 人成午夜大片免费视频77777| 日韩精品 在线一区二区| 婷婷六月天在线| 久久人搡人人玩人妻精品| 久久精品人人看人人爽| 日韩精品中文字幕亚洲| 亚洲香蕉av一区二区蜜桃| 日本一高清二区视频久二区| 霍城县| 亚洲Av综合日韩精品久久久| 午夜成人无码免费看网站| 成人年无码av片在线观看|