Meet (dj+ and set)

Source: Internet
Author: User

Questions 4 met

"Story Background"

Cong is a very simple little friend. One day he was in the cafeteria when he met a peerless MM, immediately attracted to live. Just as he wanted to come up to chat, the sky suddenly black, a huge silkworms fell from the sky, unexpectedly put the MM eat down! Silkworms laughed to Cong said:" this MM, you give her something to eat, she will eat, you do not give her to eat, she died, right?" I have hid her in the deepest depths of my body, and soon she will starve to death! Cong Of course will not let this hero save the United States chance, so he immediately cast spells, into silkworms body to rescue MM !

"Problem description"  

after entering silkworms body, Cong found that silkworms's body is a a forward graph of N nodes . The location of the Cong is the number 1 node,where MM is located at the N junction point. There may be multiple paths between the two nodes, and it takes a certain amount of time to pass each route. In addition, Cong found that there are some hidden two-way roads in the maze , and it does not take any time to hide the road. Of course, there may be more than one hidden path between two nodes. Whether it's a normal road or a hidden road, a certain amount of gold coins can be obtained when the Cong first passes. Cong now from the 1 junction Point, to the MM where the N junction point. Cong Although save MM eager, but he also hope to take more gold coins, so now your goal is: to ensure that the time required to minimize the premise, take the most coins.

"input Format"  

The input file meet.in contains m2+m1+1 lines.

Line 1 contains three positive integers N,M1,and M2, respectively, representing the total number ofnodes, normal roads and hidden roads.

Line 2 to m2+1 , each line containing three positive integers a,B, C, representing ahidden road connecting a and B, The number of gold coins on the road is C.

Section M2+2 line to m2+m1+1 row, each row contains four positive integers a,B,C,D, indicating that there is a on the ordinary road to B, the number of coins on this road is C, and the time it takes to get through the road is D.

"Output format"  

The output file meet.out contains only 1 rows, the time and the number of coins required to output the optimal scheme in turn, separated by a space in the middle.

"Input and Output sample"  

Meet.in

Meet.out

4 4 1

2 3 5

1 2 8 2

3 2 5 2

3 4 6 6

1 4 10 9

8 19

"Sample Interpretation"  

The best route is 1→2→3→4, where 2→3 is the hidden road.

"Data size and conventions"  

for 10% data,n≤10,m1≤8,m2=0.

for 30% data,n≤1000,m1≤50000,m2=0.

for 50% data,n≤10000,m1≤200000,m2=0.

for other 30% data,n≤2000,m1≤60000,m2≤200.

for all the data, n≤10000,m1≤200000,m2≤1000.

The time required to pass each ordinary road and the number of gold coins obtained by each road shall not exceed .

Ensure that there is no solution, that is, there is at least one path from node 1 to node N .

For the case of m2=0, the optimal solution can be obtained directly by using Dijkstra. (Judging by the length of the path and the gold coins)

For cases where there is a hidden path, because it does not take time, the gold coin above does not take the white, and can not take time to reach another point.

So we can add the points of the hidden path and check the concentration, then connect the ordinary edge directly to the ancestors, and then the shortest possible.

(Dijkstra to use the optimized version)

#include <cstdio>#include<cstring>#include<queue>#defineN 10005using namespacestd;structx{intV,q,j,f,n;} x[200005];structe{intv,q,j; BOOL operator< (ConstE &a)Const    {        if(Q&GT;A.Q)return 1; if(Q&LT;A.Q)return 0; returnj<A.J; }};p Riority_queue<E>QQ;intFa[n],go[n],d[n],mo[n];intRead () {CharC;  while((C=getchar ()) <'0'|| C>'9'); intre=c-'0';  while((C=getchar ()) >='0'&&c<='9') Re= (re<<1) + (re<<3) +c-'0'; returnre;}intFindinta) {    intb=A;  while(Fa[a]) a=Fa[a];  while(fa[b]&&fa[b]!=a) {intt=Fa[b]; FA[B]=a;go[b]+=Go[t]; b=T; }    returnA;}voidDij () {intS=find (1); memset (d,0x3f,sizeof(d)); D[s]=0; Qq.push ((E) {s,0, Go[s]}); Go[s]=0;  while(!Qq.empty ()) {E T=qq.top (); Qq.pop ();  for(intI=x[t.v].f;i;i=X[I].N)if(t.q+x[i].q<d[x[i].v]| | (t.q+x[i].q==d[x[i].v]&&mo[x[i].v]<go[x[i].v]+t.j+X[I].J)) {D[X[I].V]=x[i].q+t.q; MO[X[I].V]=go[x[i].v]+t.j+X[I].J; //go[x[i].v]=0;Qq.push ((E) {X[I].V,D[X[I].V],MO[X[I].V]}); }    }}intMain () {Freopen ("meet.in","R", stdin), Freopen ("Meet.out","W", stdout); intN=read (), M1=read (), m2=read ();  while(m2--)    {        intU=find (Read ()), V=find (read ()), j=read (); if(U!=V) fa[v]=u,go[u]+=go[v],go[v]=0; Go[u]+=J; }     for(intI=1; i<=m1;i++)    {        intu=Find (Read ()); X[I].V=Find (Read ()); X[I].J=read (); X[I].Q=read (); X[I].N=x[u].f; X[U].F=i; if(u==x[i].v) {X[I].V=0; X[U].F=X[I].N; X[I].Q=0; X[I].J=0; X[I].N=0; Continue;    }} dij (); printf ("%d%d", d[n=find (N)],mo[n]);    Fclose (stdin), fclose (stdout); return 0;}

Meet (dj+ and set)

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.