<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答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了。然后改成優(yōu)先隊列就過了。呵呵。沒明白。不是dijkstra才得用優(yōu)先隊列么,這題為什么也要用。后面想想,應該是先后問題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
        主站蜘蛛池模板: 久久国产乱子精品免费女| 特级一级毛片免费看| 日韩精品无码免费一区二区三区 | 97人伦色伦成人免费视频| 亚洲毛片在线免费观看| 国产男女爽爽爽爽爽免费视频| 亚洲色成人网一二三区| 91精品国产免费网站| 亚洲成a人片77777群色| 91在线视频免费播放| 亚洲欧洲无卡二区视頻| 国产传媒在线观看视频免费观看| 亚洲第一第二第三第四第五第六| 免费高清av一区二区三区| 一区二区3区免费视频| 亚洲精品美女久久777777| 色猫咪免费人成网站在线观看| 亚洲精品亚洲人成在线观看麻豆| 一二三四免费观看在线电影| 亚洲av无码专区在线观看亚| 亚洲日本韩国在线| 久久99热精品免费观看动漫| 亚洲av产在线精品亚洲第一站| 国产大片91精品免费观看男同| 国产无遮挡色视频免费观看性色| 亚洲男人天堂2017| 在线中文高清资源免费观看| 美女视频免费看一区二区| 久久亚洲一区二区| 日本19禁啪啪无遮挡免费动图| xxxxxx日本处大片免费看| 亚洲视频一区调教| 日本久久久免费高清| 久久久久久免费一区二区三区| 亚洲一区二区三区91| 国产专区一va亚洲v天堂| 99re在线视频免费观看| 精品亚洲成A人在线观看青青| 亚洲女同成av人片在线观看| 成人看的午夜免费毛片| 成全视成人免费观看在线看|