Bzoj 4289 tax--Point Edge Conversion

Source: Internet
Author: User

Title: https://www.lydsy.com/JudgeOnline/problem.php?id=4289

Turn the edge into a point, the same side with a slightly connected edge, the edge of the right small to the large margin of difference, large to small 0 edge;

The first thought is to give each new point a point of the right is this point (side) of the original right, go to it with a point right, because in the original image through this side or to spend edge rights;

But it is not right to transfer the Benquan between the edges of the original image.

So it should be the edge of the original image further split into two points, the two ends of the set of points to join one, the two points between the original edge of the right;

I didn't say anything on the topic ... In short, dis is a long long;

If you just put the structure of the storage edge in the queue, you should pay attention to the structure of the W definition of LL, and must pay attention to the structure of the internal definition of the order of variables! Because (N) {...}, the notation is the emphasis order!

--and found out that the problem was-_-https://www.cnblogs.com/Zinn/p/9326302.html three months ago.

The code is as follows:

#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<vector>#include<queue>#definePB Push_backusing namespaceStd;typedefLong Longll;int Constxn=2e5+5, xm=1e5+5;intn,m,s,t,hd[xn<<1],ct,to[xn<<3],nxt[xn<<3],w[xn<<3];ll Dis[xn<<1];BOOLvis[xn<<1];structn{ll W;intId//ll (DIS)  BOOL operator< (ConstN &y)Const  {returnw<Y.W;}}; Vector<N>V[XM];p riority_queue<N>Q;intRd () {intret=0, f=1;CharCh=GetChar ();  while(ch<'0'|| Ch>'9'){if(ch=='-') f=0; Ch=GetChar ();}  while(ch>='0'&&ch<='9') ret= (ret<<3) + (ret<<1) +ch-'0', ch=GetChar (); returnf?ret:-ret;}voidAddintXintYintz) {to[++ct]=y; nxt[ct]=hd[x]; w[ct]=z; hd[x]=CT;}voidDij () { while(Q.size ()) {intx=q.top (). ID; q.pop (); if(Vis[x])Continue; vis[x]=1;  for(intI=hd[x],u;i;i=Nxt[i]) {      if(dis[u=to[i]]>dis[x]+W[i]) Dis[u]=dis[x]+w[i],q.push ((N) {-dis[u],u}); }    }}intMain () {n=rd (); M=rd (); s=0; t=2*m+1;  for(intI=1, x,y,z;i<=m;i++) {x=rd (); Y=rd (); z=Rd (); V[X].PB ((N) {z,i}); V[Y].PB ((N) {z,i+m}); Add (I,i+M,Z); Add (i+m,i,z); }   for(intI=0; i<v[1].size (); i++) Add (s,v[1][i].id,v[1][I].W);  for(intI=0; I<v[n].size (); i++) Add (v[n][i].id,t,0);//0   for(intI=1; i<=n;i++) {sort (V[i].begin (), V[i].end ());  for(intj=1; J<v[i].size (); j + +) Add (v[i][j-1].id,v[i][j].id,v[i][j].w-v[i][j-1].W), add (v[i][j].id,v[i][j-1].id,0); } memset (Dis,0x3f,sizeofdis); Dis[s]=0; Q.push ((N) {0, S});   Dij (); printf ("%lld\n", dis[t]); return 0;}

Bzoj 4289 tax--Point Edge Conversion

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.