bzoj4331:jsoi2012 Jailbreak Tiger Bridge

Source: Internet
Author: User

DescriptionHere, is the beautiful Nanjing, here is the graceful pilgrimage river, here is the comfortable bridge of the tiger. if said into Xianghe beauty, beauty in its beautiful scenery, rather than the beauty in the comfortable Nanjing Classical alley-style life. If the Xianghe of the charming, in its simple folk, rather than that is buried in the history of the secret attracts people curious heart. Perhaps a lot of people remember, Tiger Bridge prison, the northern period of the largest prison in southern China, in nearly a century, the face of the Manchu, Northern, Republic, the new Chinese several dynasties, the name of the vicissitudes of change, all of them. people today, I am afraid, it is difficult to believe that how many thrilling things have been staged here. It was the winter of 1948, Nanjing Underground Organization of a team decided to attack Tiger Bridge prison, rescued the trapped hundreds of people. At that time, the Tiger Bridge prison, was surrounded by the N-layer grid, from the inside out, sequentially numbered,..., N. The 1th layer is connected with high voltage power. There is a M-wire, connected to all the grid, wherein the article I wire connected to the AI and bi-layer grid, if you want to destroy the first line I, need to use at least TI agent. Faced with so many layers of power grid, the attack team worried. At least one layer of the grid needs to be destroyed, otherwise it will not be successful. However, the cunning spy knew the matter, in order to destroy the attack plan, the enemy secretly added a line of tension, not to let the members of the attack squad to find. in order to be able to sneak the success, regardless of the new secret high-voltage line is connected to which two layers of power grid, the team must be destroyed and only to destroy a high-voltage line, so that at least one layer of power grid without power. Note that for new HV lines, we don't know how many agents are needed to successfully destroy them. Now, the question is, how many agents does the attack squad need at least? the Showdown is tonight! InputThe first line has 2 integers, n and M, each representing the number of grid layers and the number of HV lines. after M lines, each line is 3 integers, namely AI, Bi, and Ti. OutputThe output has only one row and contains an integer representing the minimum number of agents to use. If the plan inevitably fails, then output-1. Side of the double-link in the side of the delete does not affect the status of Unicom, so the first contraction point, leaving the cutting edge, the problem into a tree to take a path, so that the minimum value of the edge is not covered by the maximum, you can direct tree-shaped DP
#include <cstdio>#defineG *++ptrConst intn=500007, inf=0x3f3f3f3f;Charbuf[n* -],*ptr=buf-1;int _(){    intx=0, c=G;  while(c< -) c=G;  while(c> -) x=x*Ten+c- -, c=F; returnx;}BOOLei[n*4];intn,m,es[n*6],enx[n*6],ev[n*6],e0[n],e1[n],ep=2, ID[N],IDP;voidAeint*e,intAintBintc) {ES[EP]=b;enx[ep]=e[a];ev[ep]=c;e[a]=ep++; ES[EP]=a;enx[ep]=e[b];ev[ep]=c;e[b]=ep++;}intdfn[n],low[n],tk=0;voidminsint&a,intb) {if(a>b) a=b;}voidMAXS (int&a,intb) {if(a<b) a=b;}intMinintAintb) {returnA<b?a:b;}intMaxintAintb) {returnA>b?a:b;}voidTjintW) {Dfn[w]=low[w]=++tk;  for(intI=e0[w];i;i=Enx[i]) {        intu=Es[i]; if(!u)Continue; if(!Dfn[u]) {Es[i^1]=0;            TJ (U); Es[i^1]=W;            mins (Low[w],low[u]); if(Low[u]>dfn[w]) ei[i>>1]=1; }Elsemins (Low[w],dfn[u]); }}voidF1 (intW) {Id[w]=IDP; DFN[W]=0;  for(intI=e0[w];i;i=Enx[i]) {        intu=Es[i]; if(!ei[i>>1]&&Dfn[u]) F1 (U); }}intv0[n],v02[n],v1[n],v2[n],vu[n],v,ans=0;voidF2 (intWintPA) {V0[w]=v02[w]=v1[w]=v2[w]=vu[w]=inf;  for(intI=e1[w];i;i=Enx[i]) {        intu=Es[i]; if(U==PA)Continue;        F2 (U,W); V=min (v0[u],ev[i]); V2[W]=Max (min (v2[w],v), Min (V1[w],v1[u])); V1[W]=Max (min (v1[w],v), Min (V0[w],v1[u])); if(V<=v0[w]) v02[w]=v0[w],v0[w]=v; Elsemins (v02[w],v); }}voidF3 (intWintPA) {v=min (vu[w],v2[w]);    Maxs (ANS,V);  for(intI=e1[w];i;i=Enx[i]) {        intu=Es[i]; if(U==PA)Continue; Vu[u]=min (min (ev[i],vu[w]), Min (V0[u],ev[i]) ==v0[w]?v02[w]:v0[w]);    F3 (U,W); }}intMain () {fread (buf,1,sizeof(BUF), stdin) [buf]=0; N=_ (); m=_();  for(intI=0, a,b,c;i<m;++i) {a=_ (); B=_ (); c=_(); if(a==b)Continue;    AE (e0,a,b,c); } TJ (1); for(intI=1; i<=n;++i)if(Dfn[i]) {++IDP;    F1 (i); }     for(intI=2; i<ep;i+=2)if(ei[i>>1]) AE (e1,id[es[i]],id[es[i^1]],ev[i]); F2 (1,0); F3 (1,0); if(Ans==inf) ans=-1; printf ("%d", ans); return 0;}

bzoj4331:jsoi2012 Jailbreak Tiger Bridge

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.