日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Cow Toll Paths(floyd变形)

發(fā)布時間:2024/9/3 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Cow Toll Paths(floyd变形) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

鏈接:https://ac.nowcoder.com/acm/contest/1077/K
來源:牛客網(wǎng)

時間限制:C/C++ 1秒,其他語言2秒
空間限制:C/C++ 32768K,其他語言65536K
64bit IO Format: %lld
題目描述
Like everyone else, FJ is always thinking up ways to increase his revenue. To this end, he has set up a series of tolls that the cows will pay when they traverse the cowpaths throughout the farm.
The cows move from any of the N (1 <= N <= 250) pastures conveniently numbered 1…N to any other pasture over a set of M (1 <= M <= 10,000) bidirectional cowpaths that connect pairs of different pastures Aj and Bj (1 <= Aj <= N; 1 <= Bj <= N). FJ has assigned a toll Lj (1 <= Lj <= 100,000) to the path connecting pastures Aj and Bj.
While there may be multiple cowpaths connecting the same pair of pastures, a cowpath will never connect a pasture to itself. Best of all, a cow can always move from any one pasture to any other pasture by following some sequence of cowpaths.
In an act that can only be described as greedy, FJ has also assigned a toll Ci (1 <= Ci <= 100,000) to every pasture. The cost of moving from one pasture to some different pasture is the sum of the tolls for each of the cowpaths that were traversed plus a single additional toll that is the maximum of all the pasture tolls encountered along the way, including the initial and destination pastures.
The patient cows wish to investigate their options. They want you to write a program that accepts K (1 <= K <= 10,000) queries and outputs the minimum cost of trip specified by each query. Query i is a pair of numbers si and ti (1 <= si <= N; 1 <= ti <= N; si != ti) specifying a starting and ending pasture.
Consider this example diagram with five pastures:
The ‘edge toll’ for the path from pasture 1 to pasture 2 is 3. Pasture 2’s ‘node toll’ is 5.
To travel from pasture 1 to pasture 4, traverse pastures 1 to 3 to 5 to 4. This incurs an edge toll of 2+1+1=4 and a node toll of 4 (since pasture 5’s toll is greatest), for a total cost of 4+4=8.
The best way to travel from pasture 2 to pasture 3 is to traverse pastures 2 to 5 to 3. This incurs an edge toll of 3+1=4 and a node toll of 5, for a total cost of 4+5=9.
輸入描述:

  • Line 1: Three space separated integers: N, M, and K
  • Lines 2…N+1: Line i+1 contains a single integer: Ci
  • Lines N+2…N+M+1: Line j+N+1 contains three space separated integers: Aj, Bj, and Lj
  • Lines N+M+2…N+M+K+1: Line i+N+M+1 specifies query i using two space-separated integers: si and ti
    輸出描述:
  • Lines 1…K: Line i contains a single integer which is the lowest cost of any route from si to ti
    示例1
    輸入
    復(fù)制
5 7 2 2 5 3 3 4 1 2 3 1 3 2 2 5 3 5 3 1 5 4 1 2 4 3 3 4 4 1 4 2 3

輸出
復(fù)制

8 9

/*
考察對floyd的理解。
本題要求 加上 所選路徑中 點權(quán)最大值的 最短路徑。
本題難點就在于更新 所選路徑中 點權(quán) 最大值。
而floyd中 中轉(zhuǎn)點的順序 是可以隨意的,
抓住這點按點權(quán)從小到大排序,
然后 重新 給點編號。
如果此時中轉(zhuǎn)點可以松弛本條路徑,
那么此時本條路徑點券最大值肯定是當(dāng)前中轉(zhuǎn)點的點權(quán)。
*/

#include <bits/stdc++.h>using namespace std; const int MAXN = 260; const int INF = 0x3f3f3f3f; int dis[MAXN][MAXN]; int ans[MAXN][MAXN]; int n,m,q; struct Node {int c;int id;bool operator <(const Node &x)const{return c < x.c;} } node[MAXN]; int myIndex[MAXN]; void init() {for(int i = 1; i <= n; i++){for(int j = i; j <= n; j++){if(i == j){dis[i][j] = 0;ans[i][j] = node[i].c;}else{dis[i][j] = dis[j][i] = INF;ans[i][j] = ans[j][i] = INF;}}} } void floyd() {for(int k = 1; k <= n; k++){for(int i = 1; i <= n; i++){for(int j = 1; j <= n; j++){if(i == j) continue;dis[i][j] = min(dis[i][j],dis[i][k]+dis[k][j]);ans[i][j] = min(ans[i][j],dis[i][j]+max(node[i].c,max(node[k].c,node[j].c)));}}} } int main() {cin>>n>>m>>q;for(int i = 1; i <= n; i++){cin>>node[i].c;node[i].id = i;}sort(node+1,node+n+1);for(int i = 1; i <= n; i++){myIndex[node[i].id] = i;}init();int x,y,v;while(m--){cin>>x>>y>>v;x = myIndex[x];y = myIndex[y];//可能有多條邊,選最小的dis[x][y] = dis[y][x]= min(dis[x][y],v);}floyd();while(q--){cin>>x>>y;x = myIndex[x];y = myIndex[y];cout<<ans[x][y]<<endl;}return 0; }

總結(jié)

以上是生活随笔為你收集整理的Cow Toll Paths(floyd变形)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 97久久精品 | 亚洲av无码乱码国产精品 | 琪琪av在线 | 交专区videossex另类 | 大屁股白浆一区二区 | 中国在线观看视频高清免费 | 伊人网在线| 国产自产在线视频 | 在线播放日韩 | 山村大伦淫第1部分阅读小说 | 天天看天天爽 | 日韩黄色成人 | 超碰免费在线 | 日本免费在线 | 91亚洲精华国产精华精华液 | av观看网站| 国产成人在线看 | 天天爽夜夜爽夜夜爽精品 | 性欧美丰满熟妇xxxx性久久久 | 国产69精品久久久久久久 | 久久综合一区 | 人人舔人人 | 香蕉视频99 | 国产粉嫩av | 男男免费视频 | 丰满人妻老熟妇伦人精品 | 亚洲一区二区成人 | 快播在线视频 | 亚洲精品一区二区三区在线 | 久久久久国产精品区片区无码 | 日韩欧美中文字幕一区二区三区 | 四虎国产精品成人免费入口 | 奇米狠狠干 | 狠狠干干干 | 97福利| 精品在线视频免费观看 | 精品国产一区二区三区久久久久久 | 精人妻一区二区三区 | 国产精品美女久久久久久久 | 亚洲视频黄| 国产精品一区二区免费看 | 国产裸体视频网站 | www午夜视频 | 办公室荡乳欲伦交换bd电影 | 88xx成人永久免费观看 | 成人免费黄色大片v266 | 长篇高h乱肉辣文 | 国产精品伦子伦免费视频 | 国产三级黄色 | 国产欧美一区二区精品忘忧草 | 亚洲色图一区二区 | aⅴ天堂网 | 日韩一区二区视频在线观看 | 一级特黄色片 | 欧美老女人bb | 日韩精品电影在线 | 久久观看 | 欧美操穴视频 | 国产xxx在线 | 久久精品亚洲精品国产欧美 | 91热精品| 欧美伊人网 | 日韩欧美中文字幕一区二区三区 | av成人免费在线观看 | 日韩中文字幕av电影 | 国产精品4区 | 秋霞午夜伦理 | 日韩视频免费观看高清完整版 | 国产超91| 国产高清视频一区 | 男女高h视频 | 麻豆精品自拍 | 在线看黄色片 | 中日毛片 | 久久久久久久久久网站 | 国产13页| 国产成年无码久久久久毛片 | 一级中国毛片 | 日韩在线综合 | 性色av一区二区三区在线观看 | 999视频| 精品成人av一区二区在线播放 | exo妈妈mv在线播放高清免费 | www精品视频| 黄色片女人| 三级网站在线 | 亚洲AV无码成人精品国产一区 | 91久久免费 | 欧美国产一区二区在线观看 | 男操女视频网站 | 91精品国产综合久久久久久久 | 美女无遮挡免费网站 | caoporn人人| 久久国产精品首页 | 欧美作爱视频 | 激情六月天婷婷 | 黄色一级网站 | 女同另类之国产女同 | 在线观看免费毛片 |