国产99久久精品_欧美日本韩国一区二区_激情小说综合网_欧美一级二级视频_午夜av电影_日本久久精品视频

最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
當前位置: 首頁 - 科技 - 知識百科 - 正文

CodeforcesRound#257(Div.2)D題:JzzhuandCities刪特殊邊的最短路_html/css

來源:懂視網 責編:小采 時間:2020-11-27 15:54:23
文檔

CodeforcesRound#257(Div.2)D題:JzzhuandCities刪特殊邊的最短路_html/css

CodeforcesRound#257(Div.2)D題:JzzhuandCities刪特殊邊的最短路_html/css_WEB-ITnose:D. Jzzhu and Cities time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Jzzhu is the president of country A. There are n cities numbered from 1 to n in his countr
推薦度:
導讀CodeforcesRound#257(Div.2)D題:JzzhuandCities刪特殊邊的最短路_html/css_WEB-ITnose:D. Jzzhu and Cities time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Jzzhu is the president of country A. There are n cities numbered from 1 to n in his countr

D. Jzzhu and Cities

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Jzzhu is the president of country A. There are n cities numbered from 1 to n in his country. City 1 is the capital of A. Also there are mroads connecting the cities. One can go from city ui to vi (and vise versa) using the i-th road, the length of this road is xi. Finally, there are k train routes in the country. One can use the i-th train route to go from capital of the country to city si (and vise versa), the length of this route is yi.

Jzzhu doesn't want to waste the money of the country, so he is going to close some of the train routes. Please tell Jzzhu the maximum number of the train routes which can be closed under the following condition: the length of the shortest path from every city to the capital mustn't change.

Input

The first line contains three integers n,?m,?k (2?≤?n?≤?105; 1?≤?m?≤?3·105; 1?≤?k?≤?105).

Each of the next m lines contains three integers ui,?vi,?xi (1?≤?ui,?vi?≤?n; ui?≠?vi; 1?≤?xi?≤?109).

Each of the next k lines contains two integers si and yi (2?≤?si?≤?n; 1?≤?yi?≤?109).

It is guaranteed that there is at least one way from every city to the capital. Note, that there can be multiple roads between two cities. Also, there can be multiple routes going to the same city from the capital.

Output

Output a single integer representing the maximum number of the train routes which can be closed.

Sample test(s)

input

5 5 31 2 12 3 21 3 33 4 41 5 53 54 55 5

output

input

2 2 31 2 22 1 32 12 22 3

output


思路:這題只要引入一個最短路條數,然后再遍歷火車線,如果最短路與火車線長度相等,此時如果最短路條數是1的話,那說明這個最短路就是火車線,不能去掉,如果最短路條數大于1條,說明除了這條火車線外還有別的跟他同樣短的路,可以去掉;如果火車線長度比最短路長的話,顯然可以去掉。

這題剛開始看確實挺蛋疼的,比賽的時候也沒啥想法。好久不做圖論方面的了,所以有點不會了。

剛才敲spfa還重新看了下這算法才會手敲,確實有點生了。

剛開始queue沒過,T了。然后改成優先隊列就過了。呵呵。沒明白。不是dijkstra才得用優先隊列么,這題為什么也要用。后面想想,應該是先后問題T了。

#include#include#include#include#include#include#include#include#define mem(a,b) memset(a,b,sizeof(a))#define INF 1000000070000using namespace std;typedef long long ll;typedef unsigned long long ull;int cnt,n,head[900005],vis[900005];int repeat[900005];//記錄重復的邊ll dist[900005],Map[900005];struct node{ int v,next,w;} e[900005];void add(int u,int v,int w){ e[cnt].v=v; e[cnt].w=w; e[cnt].next=head[u]; head[u]=cnt++;}void spfa(){ int i,j; priority_queueq; for(i=0; i<=n; i++) dist[i]=INF; repeat[1]=1; q.push(1); vis[1]=1; dist[1]=0; while(!q.empty()) { int u=q.top(); q.pop(); vis[u]=0; for(i=head[u]; i!=-1; i=e[i].next) { if(dist[e[i].v]>dist[u]+e[i].w) { dist[e[i].v]=dist[u]+e[i].w; repeat[e[i].v]=repeat[u]; if(!vis[e[i].v]) { vis[e[i].v]=1; q.push(e[i].v); } } else if(dist[e[i].v]==dist[u]+e[i].w) { repeat[e[i].v]+=repeat[u]; if(repeat[e[i].v]>=2) repeat[e[i].v]=2; } } }}int main(){ int m,k,i,j,u,v,w,sum=0;//sum表示需要保留的火車線路 mem(head,-1); cin>>n>>m>>k; for(i=0;i<=n;i++) Map[i]=INF; for(i=0; iw) Map[v]=w; } for(i=1; i<=n; i++) { if(Map[i]!=INF) { add(1,i,Map[i]); add(i,1,Map[i]); sum++; } } spfa(); for(i=1; i<=n; i++) if(Map[i]!=INF) { if(dist[i]==Map[i]&&repeat[i]==2) sum--; else if(dist[i]

聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文檔

CodeforcesRound#257(Div.2)D題:JzzhuandCities刪特殊邊的最短路_html/css

CodeforcesRound#257(Div.2)D題:JzzhuandCities刪特殊邊的最短路_html/css_WEB-ITnose:D. Jzzhu and Cities time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Jzzhu is the president of country A. There are n cities numbered from 1 to n in his countr
推薦度:
  • 熱門焦點

最新推薦

猜你喜歡

熱門推薦

專題
Top
主站蜘蛛池模板: 成人精品一区二区www | 婷婷综合色 | 国产一区二区自拍视频 | 亚洲精品在线视频 | 国产精品久久久精品三级 | 国产不卡视频在线播放 | 精品久久综合一区二区 | 精品视频第一页 | 国产精品亚洲专区在线观看 | 在线观看欧美日韩 | 精品一区二区三区亚洲 | 欧美第一区 | 欧美不卡激情三级在线观看 | 91视频一区二区三区 | 国产在线精品成人一区二区三区 | 亚洲欧洲日韩国产 | 九色91丨porny加精 | 久久久久免费精品国产小说 | 亚洲欧美日韩中文字幕一区二区三区 | 小处雏高清一区二区三区 | 美日韩在线视频 | 国产精品麻豆 | 欧美 亚洲 中文字幕 | 国产一区二区日韩欧美在线 | 日韩视频在线播放 | 久久青青视频 | 91午夜精品亚洲一区二区三区 | 成人免费视频一区二区 | zozozo欧美人禽交另类视频 | 欧美成人精品一区二区三区 | 日本色图在线观看 | 国产一区二区网站 | 欧美一区二区三区在线观看 | 亚欧洲精品在线视频免费观看 | 久久久久久久国产精品 | 一级网站在线观看 | 日韩综合网站 | 国产视频不卡 | 日韩成人在线观看 | 国产精品第十页 | 亚洲欧美在线观看视频 |