[Vijos p1880] strongswan force

Source: Internet
Author: User

 

It is said that this is a question of joi? I think it's pretty good ~

 

The question looks terrible, but the code is still very short.

Obviously, ans are divided into three parts: 1. Increase the light pressure time in the middle; 2. Reduce the light pressure time in the middle; 3. The total time of all routes

It is found that if the minimum optical pressure value of each pillar is 0, the optical pressure will be the same at any time.

Because if the optical pressure is less than or equal to 0 in a certain moment, we can adjust the optical pressure as needed, so that we no longer need to manually reduce the optical pressure, no matter how the final optical pressure must be E [end point]

So

1. Optical pressure is the same at any time

However, we found that the time needed to reduce one optical pressure on the path is the same as the time needed to manually adjust one optical pressure on the optical column.

The optical pressure difference is the time difference.

We use Dist [N] to represent the photopressure at point N.

2. x-Dist [endpoint] = light pressure reduction time in the middle + total time of all routes

From 1 to E [endpoint]-Dist [endpoint] = the time for increasing the optical pressure in the middle

The two formulas decrease with the increase of DIST [endpoint]

You only need to calculate the maximum Dist [endpoint], which is why we need to use the shortest path.

Ans = (X-Dist [end point]) + (E [end point]-Dist [End Point) = x + E [end point]-2 * Dist [end point]

 

 1 #include <cstdio> 2 #include <queue> 3 #include <algorithm> 4 typedef std::pair<long long, int> node; 5 const long long INF=0x7FFFFFFFFFFFFFLL; 6 const int sizeOfPoint=100001; 7 const int sizeOfEdge=600006; 8  9 struct edge {int point, dist; edge * next;};10 edge memory[sizeOfEdge], * port=memory;11 edge * e[sizeOfPoint];12 inline edge * newedge(int point, int dist, edge * next)13 {14     edge * ret=port++;15     ret->point=point; ret->dist=dist; ret->next=next;16     return ret;17 }18 19 int N, M, X;20 int E[sizeOfPoint];21 long long dist[sizeOfPoint];22 std::priority_queue<node> q;23 inline long long min(long long x, long long y) {return x<y?x:y;}24 inline int getint();25 inline void putint(long long);26 27 int main()28 {29     N=getint(), M=getint(), X=getint();30     for (int i=1;i<=N;i++) E[i]=getint();31     for (int i=0;i<M;i++)32     {33         int A, B, T;34         A=getint(), B=getint(), T=getint();35         if (E[A]>=T) e[A]=newedge(B, T, e[A]);36         if (E[B]>=T) e[B]=newedge(A, T, e[B]);37     }38 39     for (int i=1;i<=N;i++) dist[i]=-INF;40     for (q.push(node(X, 1));!q.empty(); )41     {42         node u=q.top(); q.pop();43         if (dist[u.second]!=-INF) continue;44         dist[u.second]=u.first;45         for (edge * i=e[u.second];i;i=i->next)46             q.push(node(min(u.first-i->dist, E[i->point]), i->point));47     }48 49     if (dist[N]==-INF) printf("-1\n");50     else putint(X+E[N]-(dist[N]<<1));51 52     return 0;53 }54 inline int getint()55 {56     register int num=0;57     register char ch;58     do ch=getchar(); while (ch<‘0‘ || ch>‘9‘);59     do num=num*10+ch-‘0‘, ch=getchar(); while (ch>=‘0‘ && ch<=‘9‘);60     return num;61 }62 inline void putint(long long num)63 {64     char stack[22];65     register int top=0;66     if (num==0) stack[top=1]=‘0‘;67     for ( ;num;num/=10) stack[++top]=num%10+‘0‘;68     for ( ;top;top--) putchar(stack[top]);69     putchar(‘\n‘);70 }
This silly installation of Series B

 

[Vijos p1880] strongswan force

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.