bzoj2753: [SCOI2012] ski with time capsule

Source: Internet
Author: User

2753: [SCOI2012] Ski with time capsule limit:50 Sec Memory limit:128 MB
submit:2060 solved:720
[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.

Find the smallest tree diagram .... And then see the data range the whole person is ignorant ... Run to the membrane of the puzzle ..... Because only from high to low, so the non-edge can be viewed as a side, and then according to the topic meaning is to give you a map of the smallest, and then if you use the Liu algorithm to calculate, you can only get70 points. This problem has a different place from the rest of the smallest tree diagram: Points have height! is the height just converted to a forward edge? Of course not. RecallKruskal Why can't we ask for the smallest tree diagram? Because every time the smallest side is a direction, so after the completion of the algorithm can not guarantee that the root to the son, there may be a reverse side! But the opposite side of the problem will only appear between the points with the same height. If the edge is first sorted by the end height of the first keyword, the edge length for the second keyword after sorting, it will be guaranteed priority to high, the same high point between the selection of small edges, and then there will be no reverse situation, so you can useThe Kruskal implements the time complexity of O (Mlog (m)) to solve this problem.
#include <bits/stdc++.h>#defineN 2023333#defineRep (i,l,r) for (int i=l;i<=r;i++)using namespacestd; typedefLong Longll; structzs{intu,v;    ll W;    }s[n],c[n]; structedge{intTo,next;        }e[n];    ll ans; intR,x,y,f[n],tot,cnt,head[n],m,n,now; intH[n]; intFindintx) {if(f[x]==x)returnXElse returnf[x]=find (f[x]); }    BOOLVis[n]; voidInsintUintv) {e[++tot].to=v; E[tot].next=head[u]; head[u]=tot; }    voidDfsintx) {vis[x]=1; ++R;  for(intK=head[x];k;k=e[k].next)if(!vis[e[k].to]) DFS (e[k].to); }    BOOLCMP (ZS A,zs b) {if(H[A.V]==H[B.V])returna.w<b.w;Else returnH[a.v]>H[B.V]; }    intMain () {scanf ("%d%d",&n,&m); Rep (I,1, N) scanf ("%d",&H[i]); Rep (I,1, M) {scanf ("%d%d",&x,&y); if(h[x]>=H[y]) ins (x, y); if(h[x]<=H[y]) ins (y,x); S[I].U=x; S[i].v=y; scanf"%lld",&S[I].W); } DFS (1); Rep (I,1, m)if(Vis[s[i].u] &&VIS[S[I].V]) {x=s[i].u; y=s[i].v; if(H[x]>=h[y]) c[++cnt].u=x,c[cnt].v=y,c[cnt].w=S[I].W; if(H[x]<=h[y]) c[++cnt].u=y,c[cnt].v=x,c[cnt].w=S[I].W; } sort (c+1, c+1+cnt,cmp); Rep (I,1, N) f[i]=i; printf ("%d", R); Rep (I,1, CNT) {x=find (C[I].U); y=find (C[I].V); if(x!=y) {f[x]=y; ++Now ; Ans+=(ll) C[I].W; }              if(now+1==R) Break; } printf ("%lld", ans); }
View Code

bzoj2753: [SCOI2012] 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.