Uvaoj 10048 - Audiophobia(Floyd演算法變形)

來源:互聯網
上載者:User

標籤:style   blog   http   color   os   io   for   2014   

 

1 /* 2 題目大意: 3 從一個點到達另一個點有多條路徑,求這多條路經中最大噪音值的最小值! 、 4 5 思路:最多有100個點,然後又是多次查詢,想都不用想,Floyd演算法走起! 6 */ 7 #include<iostream> 8 #include<cstring> 9 #include<cstdio>10 #define INF 0x3f3f3f3f11 using namespace std;12 13 int map[105][105];14 15 int main(){16 int n, m, q;17 int u, v, d;18 int cnt=0;19 scanf("%d%d%d", &n, &m, &q);20 while((n || m || q)){21 memset(map, 0x3f, sizeof(map));22 while(m--){23 scanf("%d%d%d", &u, &v, &d);24 map[u][v]=map[v][u]=d; 25 }26 for(int k=1; k<=n; ++k)27 for(int i=1; i<=n; ++i)28 for(int j=1; j<=n; ++j){29 int dd=max(map[k][j], map[i][k]);30 if(map[i][j] > dd)31 map[i][j] = dd; 32 }33 printf("Case #%d\n", ++cnt);34 while(q--){35 scanf("%d%d", &u, &v);36 if(map[u][v]==INF)37 printf("no path\n");38 else39 printf("%d\n", map[u][v]);40 }41 scanf("%d%d%d", &n, &m, &q);42 if((n || m || q))43 printf("\n");44 } 45 return 0;46 }

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.