Bzoj 2753 ski with time capsule

Source: Internet
Author: User

2753: [SCOI2012] Ski with time capsule limit:50 Sec Memory limit:128 MB
submit:2006 solved:710
[Submit] [Status] [Discuss] Descriptiona180285 is very fond of skiing. He came to a snowy mountain, where M-rails and N-track intersections (and also attractions) are distributed, and each attraction has a numbered I (1<=i<=n) and a high hi. a180285 can slide from attraction I to attraction J when and only if there is an edge between I and J, and the height of I is not less than J. Unlike other skiers, a180285 likes to visit as many sights as possible with the shortest glide path. If you only visit the sights on one path, he will feel too little. So a180285 took out his carry-on time capsule. This is a magical drug that can be immediately returned to the last scenic spot after eating (without moving or being considered a a180285 distance). Please note that this magical drug is available for continuous consumption, which means that you can go back to places you've been to for a long time (such as the last scenic spot and the last visited attraction). Now, a180285 stood at the 1th sights and looked at the mountain targets, with an upsurge of emotions. He was very interested to know how to slide the shortest distance to as many attractions as possible without considering the time capsule consumption (that is, to meet the maximum number of scenic spots to minimize the overall glide distance). Can you help him find the shortest distance and the number of attractions? The first line of input inputs is a two integer n,m. The next 1 lines have n integers hi, each representing the height of each attraction. The next M-line shows the distribution of the tracks between the various attractions. 3 integers per line, Ui,vi,ki. There is a track with a length of ki between the attractions that are numbered UI and the sights numbered VI. An output line that indicates the maximum number of places the a180285 can reach, and the shortest possible glide distance at this time. Sample Input
3 3
3 2 1
1 2 1
2 3 1
1 3 10
Sample Output3 2
HINT

"Data Range"

For 30% of data, ensure 1<=n<=2000

For 100% of data, ensure 1<=n<=100000

For all data, guarantee the 1<=m<=1000000,1<=hi<=1000000000,1<=ki<=1000000000.

SolvingThis is a relatively simple question. first, the BFS to find the point can be reached, and then the naïve approach is not directly on the minimum tree diagram AhConsidering the height of the problem, this condition is certainly not intended to be directed. We found that if you add the minimum spanning tree from high to low by the end of the edge, do a Kruskal, you can guarantee to start from point 1th, can reach the point that BFS can reach just now. The same height is sorted by depth, equivalent to the same height, layered to do Kruskal
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5 using namespacestd;6 #defineMAXN 10000207 8typedefLong Longll;9 Ten intH[MAXN]; One  A structnode{ -     intu,v,w; -     BOOL operator< (Node A)Const{ the         if(min (h[u],h[v]) = = min (h[a.u],h[a.v]))returnW <A.W; -         returnMin (H[u],h[v]) >min (h[a.u],h[a.v]); -     } - }DT[MAXN]; + structnode2{ -     intnext,to; +}E[MAXN *2]; A inthead[maxn],cnt; at ll ans; - intNum,vis[maxn],n,m,q[maxn],hh,tt; - intFA[MAXN]; -  -InlinevoidAdde (intXinty) { -E[++cnt].to =y; inE[cnt].next =Head[x]; -HEAD[X] =CNT; to } + voidBFs () { -q[tt++] =1, vis[1] =1; the      while(HH <TT) { *         intx = q[hh++]; $          for(inti = head[x]; I i =E[i].next) {Panax Notoginseng             if( !Vis[e[i].to]) { -Vis[e[i].to] =1, q[tt++] =e[i].to; the             } +         } A     } the } + intGETFA (intx) { -     if(x = = Fa[x])returnx; $     returnFA[X] =GETFA (fa[x]); $ } - voidsolve () { -      for(inti =1; I <= N; i++)if(Vis[i]) num++; theSort (dt +1, DT + M +1); -      for(inti =1; I <= N; i++) Fa[i] =i;Wuyi      for(inti =1; I <= m; i++){ the         if(!vis[dt[i].u] | |!vis[dt[i].v])Continue; -         intp = GETFA (dt[i].u), q =GETFA (DT[I].V); Wu         if(P! =q) { -FA[P] =Q; AboutAns + =(ll) dt[i].w; $         } -     }     -printf"%d%lld\n", Num,ans); - } A intMain () { +scanf"%d%d",&n,&m); the      for(inti =1; I <= N; i++) scanf ("%d",&h[i]); -      for(inti =1; I <= m; i++){ $         intx,y,w; thescanf" %d%d%d",&x,&y,&W); the         if(H[x] >=H[y]) adde (x, y); the         if(H[y] >=h[x]) Adde (y,x); theDt[i] =(node) {x,y,w}; -     } in BFS (); the solve (); the     return 0; About}

Bzoj 2753 ski with time capsule

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.