Codevs 1557 熱浪

來源:互聯網
上載者:User

標籤:names   iam   dia   div   app   ++   blog   desc   天下   

1557 熱浪

  時間限制: 1 s    空間限制: 256000 KB    題目等級 : 鑽石 Diamond

題目描述 Description

德克薩斯純樸的民眾們這個夏天正在遭受巨大的熱浪!!!他們的德克薩斯長角牛吃起來不錯,可是他們並不是很擅長生產富含奶油的乳製品。Farmer John此時以先天下之憂而憂,後天下之樂而樂的精神,身先士卒地承擔起向德克薩斯運送大量的營養冰涼的牛奶的重任,以減輕德克薩斯人忍受酷暑的痛苦。

 

FJ已經研究過可以把牛奶從威斯康辛運送到德克薩斯州的路線。這些路線包括起始點和終點先一共經過T (1 <= T <= 2,500)個城鎮,方便地標號為1到T。除了起點和終點外地每個城鎮由兩條雙向道路連向至少兩個其它地城鎮。每條道路有一個通過費用(包括油費,過路費等等)。

 

給定一個地圖,包含C (1 <= C <= 6,200)條直接連接2個城鎮的道路。每條道路由道路的起點Rs,終點Re (1 <= Rs <= T; 1 <= Re <= T),和花費(1 <= Ci <= 1,000)組成。求從起始的城鎮Ts (1 <= Ts <= T)到終點的城鎮Te(1 <= Te <= T)最小的總費用。

輸入描述 Input Description

第一行: 4個由空格隔開的整數: T, C, Ts, Te

第2到第C+1行: 第i+1行描述第i條道路。有3個由空格隔開的整數: Rs, Re和Ci

輸出描述 Output Description

一個單獨的整數表示從Ts到Te的最小總費用。資料保證至少存在一條道路。

範例輸入 Sample Input

7 11 5 4

2 4 2

1 4 3

7 2 2

3 4 3

5 7 5

7 3 3

6 1 1

6 3 4

2 4 3

5 6 3

7 2 1

範例輸出 Sample Output

7

資料範圍及提示 Data Size & Hint

5->6->1->4 (3 + 1 + 3)

邊表STL的SPFA:


 
 1 #include<cstdio> 2 #include<iostream> 3 #include<cstring> 4 #include<queue> 5 using namespace std; 6 int dis[100010],u[100010],v[100100],head[100010],next[100010],exist[100010]; 7 int n,m,S,T,x,y,z,tot=0; 8 queue<int> q; 9 void bianbao(int x,int y,int z){10     u[++tot]=y;11     v[tot]=z;12     next[tot]=head[x];13     head[x]=tot;14 }15 void spfa(){16     memset(dis,127,sizeof(dis));17     dis[S]=0;18     q.push(S);19     exist[S]=1;20     while(!q.empty()){21         int p=q.front();22         q.pop();23         exist[p]=0;24         for(int i=head[p];i;i=next[i])25             if(dis[u[i]]>dis[p]+v[i]){26                 dis[u[i]]=dis[p]+v[i];27                 if(!exist[u[i]]){28                     exist[u[i]]=1;29                     q.push(u[i]);30                 }31             }32     }33     printf("%d\n",dis[T]);34 }35 int main()36 {37     scanf("%d%d%d%d",&n,&m,&S,&T);38     for(int i=1;i<=m;i++){39         scanf("%d%d%d",&x,&y,&z);40         bianbao(x,y,z);bianbao(y,x,z);41     }42     spfa();43     return 0;44 }

 

剛開始STL忘了pop,結果全逾時了~~~

 

 

Codevs 1557 熱浪

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.