bzoj4398: Fu Hui Shuang Xiu

Source: Internet
Author: User

Learning the shortest position, this method of building the map is very good, although it will not prove correct ...

#include <bits/stdc++.h>#defineN 220000#defineINF 1000000000using namespacestd;intN, M;intAi[n], bi[n], ci[n], di[n];intcheck;classdij{Private:    structNode {intT, D;}; structcomp {int operator() (Node A, Node B) {returnA.D >B.D;}}; Priority_queue<node, Vector <node>, comp>Q; Public: Vector<int>Bi[n], ci[n]; intDis[n], vis[n], pre[n]; inttot; voidBuildintAintBintc) {bi[a].push_back (b); Ci[a].push_back (c); //if (check) printf ("%d%d%d\n", a,b,c);     }    voidsolve () { for(inti =2; I <= tot; + + i) dis[i] = INF, vis[i] =0; dis[1] = vis[1] =0; Q.push (node) {1,0});  while(!Q.empty ()) {            intHD;  DoHD =q.top (). T, Q.pop ();  while(VIS[HD] &&!q.empty ()); if(VIS[HD]) Break;ElseVIS[HD] =1;  for(intj =0; J < Bi[hd].size (); ++j)if(DIS[HD] + ci[hd][j] <Dis[bi[hd][j]]) {Dis[bi[hd][j]]= Dis[hd] +Ci[hd][j]; PRE[BI[HD][J]]= HD = =1?Bi[hd][j]: PRE[HD];                Q.push (node) {bi[hd][j], dis[bi[hd][j]]}); }}}} A, B;intTot, ans = INF, BAC =INF, pp;intMain () {scanf ("%d%d", &n, &m); A.tot = n; B.tot = n +1;  for(inti =1; I <= m; ++i) {intA, B, C, D; scanf ("%d%d%d%d", &a, &b, &c, &d); Tot++; Ai[tot] = A; Bi[tot] = b; Ci[tot] =C; Tot++; Ai[tot] = b; Bi[tot] = A; Ci[tot] =D;        A.build (A, B, c);        A.build (b, A, d); if(A = =1|| b = =1)if(BAC > C + d) BAC = c + d, pp = (A = =1?b:a);    } a.solve (); a.dis[1] = BAC; a.pre[1] =pp; Check=1;  for(inti =1; I <= tot; ++i) {if(Ai[i] = =1)        {            if(A.pre[bi[i]]! =Bi[i]) B.build (1, Bi[i], ci[i]); }        Else if(Bi[i] = =1)        {            if(A.pre[ai[i]]! =Ai[i]) B.build (1, n +1, A.dis[ai[i]] +Ci[i]); ElseB.build (Ai[i], n +1, Ci[i]); }        Else if(A.pre[ai[i]]! =A.pre[bi[i]]) B.build (1, Bi[i], A.dis[ai[i]] +Ci[i]); ElseB.build (Ai[i], bi[i], ci[i]);    } b.solve (); printf ("%d\n", B.dis[n +1]);}

bzoj4398: Fu hui Double repair

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.