"Bzoj" 2100: [Usaco2010 dec]apple Delivery (spfa+ optimization)

Source: Internet
Author: User

http://www.lydsy.com/JudgeOnline/problem.php?id=2100

I'm going to spit it out.

I have not paid 10 times the tle.

Pop

It was a written setback.

At first, no SPFA to optimize the decisive t

And then see the puzzle added (add the wrong t_t) or tle. I just suspect the data ...

Pop

I had a wrong place to call.

This SPFA queue optimizes the true God.

#include <cstdio> #include <cstring>using namespace std; #define REP (i, n) for (int i=0; i< (n); ++i) #define F Or1 (i,a,n) for (int i= (a), i<= (n), ++i) #define FOR2 (i,a,n) for (int i= (a);i< (n), ++i) #define FOR3 (i,a,n) for (int i= (a ); i>= (n); i) #define FOR4 (i,a,n) for (int i= (a);i> (n); i) #define CC (i,a) memset (i,a,sizeof (i)) #define READ (a) a =getint () #define PRINT (a) printf ("%d", a) #define DBG (x) cout << #x << "=" << x << endl#define PR Intarr (A, N, m) Rep (AAA, N) {rep (BBB, m) cout << a[aaa][bbb]; cout << Endl;} inline const int Getint () {int r=0, k=1; char C=getchar (); for (; c< ' 0 ' | | C> ' 9 '; C=getchar ()) if (c== '-') k=-1; for (; c>= ' 0 ' &&c<= ' 9 '; C=getchar ()) r=r*10+c-' 0 '; return k*r; }inline const int MAX (const int &a, const int &b) {return a>b?a:b;} inline const int min (const int &AMP;A, const int &b) {return a<b?a:b;} const int n=100005, M=400005;int ihead[n], CNT, q[n], front, tail, d[n], N, M, X,XX, Xxx;bool vis[n];struct ED {int to, Next, W;} e[m];inline void Add (const int &AMP;U, const int &AMP;V, const int &w) {e[++cnt].next=ihead[u]; ihead[u]=cnt; e[cnt].t O=v; E[CNT].W=W;E[++CNT].NEXT=IHEAD[V]; ihead[v]=cnt; E[cnt].to=u; E[cnt].w=w;} inline void SPFA (const int &s) {memset (d, 0x3f, sizeof (int) * (n+3));d [s]=0; vis[s]=1; front=tail=0; q[tail++]=s;while (Tail!=front) {int u=q[front++], V; if (front==n) front=0; vis[u]=0;for (int i=ihead[u]; i; i=e[i].next) if (D[V=E[I].TO]&GT;D[U]+E[I].W {d[v]=d[u]+e[i].w;if (!vis[v]) {vis[v]=1;if (D[v]<d[q[front]) {--front; if (front<0) front+=n;q[front]=v;}  else {q[tail++]=v; if (tail==n) tail=0;}}}}  int main () {read (m); Read (n); read (x); read (xx); read (XXX); For1 (i, 1, m) {int u=getint (), V=getint (), W=getint (), Add (U, V, W);} SPFA (xx); int ans=d[x]+d[xxx];spfa (XXX), if (Ans>d[x]+d[xx]) ans=d[x]+d[xx];p rint (ans); return 0;}

Description

Bessie has a crisp red apples to deliver to both of her friends in the herd. Of course, she travels the C (1 <= C <= 200,000) cowpaths which is arranged as the usual graph which connects P (1 <= P <= 100,000) pastures conveniently numbered from 1..p:no Cowpath leads from a pasture to itself, Cowpaths is b Idirectional, each cowpath have a associated distance, and, best of all, it's always possible to get from any pasture to Any other pasture. Each cowpath connects, differing pastures p1_i (1 <= p1_i <= p) and p2_i (1 <= p2_i <= p) with a distance b Etween them of d_i. The sum of the distances d_i does not exceed 2,000,000,000. What's the minimum total distance Bessie must travel to deliver both apples by starting at pasture PB (1 <= PB <= P ) and visiting Pastures PA1 (1 <= PA1 <= p) and PA2 (1 <= PA2 <= p) in any order. All three of these pastures is distinct, of course. Consider this map of bracketed pasture numbers and cowpaths WITh distances:if Bessie starts at pasture [5] and delivers apples to pastures [1] and [4], she best path is:5-6-&gt ; 7, 3, 2, 1* with a total distance of 12.

A P-point of the graph, C is the right way.
CLJ to from the PB Point (Home), both to Pa1 Point Noi to win gold medal, also to Pa2 Point CMOS stadium to take gold medal. (Don't go home on the way)
You can go to NOI first, or you can go to the CMO first.
Of course God Ben Clj is sure to make the total distance minimum, output minimum value. Input

* Line 1:line 1 contains five space-separated integers:c, P, PB, PA1, and PA2 * Lines 2..c+1:line i+1 describes Cowpath I by naming II pastures it connects and the distance between Them:p1_i, P2_i, d_i

Output

* Line 1:the Shortest distance Bessie must travel to deliver both apples

Sample Input9 7 5 1 4
5 1 7
6 7 2
4 7 2
5 6 1
5 2 4
4 3 2
1 2 3
3 2 2
2 6 3



Sample Output12
HINT

to seek translation ... In the station PM me ....

Source

Silver

"Bzoj" 2100: [Usaco2010 dec]apple Delivery (spfa+ optimization)

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.