POJ1062 expensive dowry [shortest-circuit modeling]

Source: Internet
Author: User

The expensive dowry
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 45892 Accepted: 13614

Description

The young explorers came to an Indian tribe. There he fell in love with the chief's daughter, so he went to Qiuqin to the chief. The chief asked him to use 10,000 gold coins as a dowry to promise to marry his daughter. The explorers could not get so many gold coins that they asked the chief to lower their demands. The sheikh said, "Well, if you can get me the piao of the high priest, I can just have 8000 gold." If you can get his crystal ball, then just 5000 gold. The explorer ran to the high priest and demanded Piao or a crystal ball, and the high priest asked him to change it with gold coins, or to get other things for him, he could lower the price. The explorers then ran to other places, and others made similar demands, either by exchanging coins directly or by finding something else to lower the price. But there's no need for explorers to change things with a variety of things, because they won't get a lower price. Explorers now need your help so that he can marry his sweetheart with the least amount of gold. And what he's going to tell you is that in this tribe, hierarchy is very strong. No direct contact will be made between two persons with a status gap exceeding a certain limit, including transactions. He is a foreigner, so he can not be subject to these restrictions. But if he trades with a lower-level person, the higher-status person will not trade with him, they think it is indirect contact and vice versa. So you need to give him the best plan after considering all the circumstances.
For the sake of convenience, we numbered all items starting from 1, and the chief's promise was also regarded as an item, and the number was always 1. Each item has a corresponding price p, the host's status level L, as well as a series of alternatives ti and the replacement of the corresponding "preferential" Vi. If the difference in status between the two people exceeds m, it cannot be "indirectly traded". You have to figure out how much gold the adventurer needs at least to marry the chief's daughter.

Input

The input first line is two integers m,n (1 <= N <= 100), which in turn represents the status level gap limit and the total number of items. Next, according to the number from small to large in order to give a description of n items. The description of each item begins with three nonnegative integers p, L, X (x < N), which in turn indicate the price of the item, the rank of the host, and the total number of substitutes. The next x row contains two integers t and V, each representing the replacement number and the "preferential price".

Output

Output the minimum number of coins required.

Sample Input

1 410000 3 22 80003 50001000 2 14 2003000 2 14 20050 2 0

Sample Output

5250

Source

Zhejiang Orz Hzwerfigured it out, didn't expect to enumerate the lowest level0,0 the distance from the super source to any item is P, if a is a substitute for B, the distance from A to B is the preferential price; enum L for Min{d[1]}attention is arrived, not from the beginning
////main.cpp//poj1062////Created by Candy on 9/13/16.//copyright©2016 Candy. All rights reserved.//#include<iostream>#include<cstdio>#include<algorithm>#include<queue>#include<cstring>using namespacestd;Const intn= the, inf=1e9;inlineintRead () {CharC=getchar ();intx=0, f=1;  while(c<'0'|| C>'9'){if(c=='-') f=-1; c=GetChar ();}  while(c>='0'&&c<='9') {x=x*Ten+c-'0'; c=GetChar ();} returnx;}intm,n,l[n],sl[n],p,t,x,val,ans=INF;structedge{intV,w,ne;} E[n*N];intH[n],cnt=0; inlinevoidInsintUintVintW) {CNT++; E[CNT].V=v;e[cnt].w=w;e[cnt].ne=h[u];h[u]=CNT;}intD[n],inq[n],q[n*n],head=1, tail=0;voidSPFA (intmn) {     for(intI=1; i<=n;i++) d[i]=INF; d[0]=0; inq[0]=1; q[++tail]=0;  while(head<=tail) {        intu=q[head++];inq[u]=0;  for(intI=h[u];i;i=e[i].ne) {            intv=e[i].v,w=E[I].W; if(mn+m<l[v]| | L[V]&LT;MN)Continue;//{printf ("v%d\n", v); continue;}            if(d[v]>d[u]+W) {D[v]=d[u]+W; if(!inq[v]) {inq[v]=1; q[++tail]=v;} }}} ans=min (ans,d[1]);}intMainintargcConst Char*argv[]) {m=read (); n=read ();  for(intI=1; i<=n;i++) {p=read (); L[i]=sl[i]=read (); x=read (); INS (0, i,p);  while(x--) {T=read (); val=read (); Ins (t,i,val);} } sort (SL+1, sl+1+N);  for(intI=1; i<=n;i++)if(sl[i]<=l[1]) SPFA (Sl[i]); printf ("%d", ans); return 0;}

POJ1062 expensive dowry [shortest-circuit modeling]

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.