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

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

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

      <<<<<<<<學(xué)海無(wú)涯苦作舟!

      更加深入的了解SPFA

      SPFA算法是求單源路徑的經(jīng)典算法,就是一點(diǎn)到其它所有點(diǎn)的最短路徑。

      這個(gè)類(lèi)似于Flyod但是效率要高很多。下面給出具體的演示。

      Minya Konka decided to go to Fuzhou to participate in the ACM regional contest at their own expense.Through the efforts, they got a small amount of financial support from their school, but the school could pay only one of those costs between two stations for them.

      From SWUST to Fujian Normal University which is the contest organizer, there are a lot of transfer station and there are many routes.For example, you can take the bus to Mianyang Railway Station (airport), then take the train (plane) to Fuzhou,and then take a bus or taxi to the Fujian Normal University.

      The school could pay only one of those costs between two stations for them, the others paid by the Minya Konka team members.They want to know what is the minimum cost the need pay.Can you calculate the minimum cost?

      Input

      There are several test cases.

      In each case,the first line has two integers n(n<=100) and m(m<=500),it means there are n stations and m undirected roads.

      The next m lines, each line has 3 integers u,v,w,it means there is a undirected road between u and v and it cost w.(1<=u,v<=n,0<=w<=100)

      The ID of SWUST is 1,and n is the ID of Fujian Normal University.

      Output

      If they can not reach the destination output -1, otherwise output the minimum cost.

      Sample Input

      5 5
      1 2 7
      1 3 3
      3 4 3
      2 5 3
      4 5 3
      #include "iostream"
      #include "cstring"
      #include "queue"
      using namespace std;
      #define INF 999999999
      #define eMax 505
      #define nMax 105
      bool vis[nMax];
      int dis[2][nMax], num, rec[nMax], n, m;
      struct Node
      {
      int u, v, w, pre;
      }e[eMax*2];
      void Init(int u, int v, int w)
      {
      e[num].u = u;
      e[num].v = v;
      e[num].w = w;
      e[num].pre = rec[u];
      rec[u] = num++;
      }
      void spfa(int s, int p)
      {
      memset(vis, false, sizeof(vis));
      dis[p][s] = 0;
      queue<int> q;
      q.push(s);
      while(!q.empty())
      {
      s = q.front();
      q.pop();
      vis[s] = false;
      int j, v;
      for(j=rec[s]; j!=-1; j=e[j].pre)
      {
      v = e[j].v;
      if(dis[p][s] + e[j].w < dis[p][v])
      {
      dis[p][v]=dis[p][s]+e[j].w;
      if(!vis[v])
      {
      vis[v] = true;
      q.push(v);
      }
      }
      }
      }
      }
      int main()
      {
      int u, v, w;
      while(cin>>n>>m)
      {
      num = 0;
      memset(rec, -1, sizeof(rec));
      memset(dis, 0x3f, sizeof(dis));
      int ans = INF;
      while(m--)
      {
      cin>>u>>v>>w;
      Init(u, v, w);
      Init(v, u, w);
      }
      spfa(1, 0);
      spfa(n, 1);
      for(int i=0; i<num; i++)
      if(dis[0][e[i].u]+dis[1][e[i].v] < ans)
      ans = dis[0][e[i].u]+dis[1][e[i].v];
      if(ans < INF) cout<<ans<<endl;
      else cout<<"-1"<<endl;
      }
      }
      在上面的代碼中我們用了一個(gè)二維的數(shù)組來(lái)分別保留
      1到其它所有點(diǎn)的最短距離和n到其它所有點(diǎn)的最短距離。
      就是這樣,這個(gè)就是SPFA。

      posted on 2011-11-26 10:38  More study needed.  閱讀(374)  評(píng)論(0)    收藏  舉報(bào)

      導(dǎo)航

      書(shū)山有徑勤為路>>>>>>>>

      <<<<<<<<學(xué)海無(wú)涯苦作舟!

      主站蜘蛛池模板: 老师破女学生处特级毛ooo片| 石柱| 亚洲乱理伦片在线观看中字| 亚洲欧美综合中文| 中文字幕在线日韩| 性做久久久久久久| 日韩人妻少妇一区二区三区| 少妇精品无码一区二区免费视频| 在线观看国产区亚洲一区| 国内不卡不区二区三区| 自拍偷亚洲产在线观看| 亚欧洲乱码视频在线专区| 亚洲自在精品网久久一区| 影音先锋AV成人资源站在线播放 | 又湿又紧又大又爽a视频| 精品国产中文字幕在线| 国产短视频一区二区三区| 国产老女人精品免费视频| 亚洲精品欧美综合二区| 九九热精品在线视频免费| 爆乳2把你榨干哦ova在线观看 | 中文字幕久区久久中文字幕| 亚洲欧美自偷自拍视频图片| av无码精品一区二区三区四区 | 精品一区二区三区少妇蜜臀| 欧美xxxxhd高清| 亚洲精品揄拍自拍首页一| 国产亚洲精品成人无码精品网站| 亚洲va久久久噜噜噜久久狠狠| 亚洲av色综合久久综合| 亚洲欧美综合精品成| 麻豆国产97在线 | 欧美| 国产精品日韩中文字幕| 国产精品久久久久久久久久| 一本大道久久香蕉成人网| 99久久精品国产亚洲精品| 国内精品免费久久久久电影院97| 国产精品久久久久9999高清| 麻豆蜜桃伦理一区二区三区 | 五月婷之久久综合丝袜美腿| 国产精品美女久久久久久麻豆|