Bzoj 2542: [Ctsc2001] Ultimate Intelligence Stream

Source: Internet
Author: User

Topic links 2542: [Ctsc2001] Ultimate Intelligence time limit:1 Sec Memory limit:128 MB
submit:321 solved:125
[Submit] [Status] [Discuss] Description

Before the end of the Normandy landings, the Allied and German intelligence agencies launched an unprecedented intelligence war around the final landing site.
In this intelligence war, the Allies ' tactics were to use the double spies lurking inside the enemy, to release false landing messages to the enemy's intelligence agencies. The spies who have infiltrated the enemy lines are the elite of Allied intelligence, but how to choose the right person, and the best way to deliver the message, can ensure that false messages can be delivered as quickly and safely as possible to the German commanders ' ears, the biggest problem plaguing the Allied intelligence Minister. He needs your help.

The following is the operational information provided by the Intelligence Minister:

Behind the enemy lines are lurking in our best n Spy, respectively, with the number 1, 2, ..., n number. Within a given combat time, there is a maximum of one point-to-point double contact between any two persons.
I will give you a form that will provide a safe degree of connection between any two spies I and J, expressed as a real Si J of [0, 1]; The maximum number of messages that can be communicated to each other when they are contacted, with a positive integer representing Mi j (if not mentioned in the table, So there is no direct connection between Spy I and J.
It is not absolutely safe to pass the false message from the Allied headquarters to every spy's hand, and we use the real ASJ [0, 1] to indicate the level of security between HQ and Spy J, and AMJ is the maximum number of messages that are delivered when contact between headquarters and Spy J is reached. For spies who do not have direct contact with headquarters, his amj=0 (and his ASJ in the table are meaningless).
Of course, the process of false news from the spy hand to the enemy intelligence officer's desk is absolutely safe, that is to say, the spy and the enemy Intelligence department either do not direct contact, or the security of its connection is 1 (that is, completely reliable).

Now the Intelligence Department intends to "reveal" the K false news to the Germans. The news was first sent by headquarters to some of the N spies, and then through the intelligence of their communication, and finally by some of the N spies to send information to the German hands.
For a message, only the safe passage of all the transit process to the enemy Intelligence department, the transmission of the message is safe; therefore, according to the multiplication principle, its security degree p is from the head office, through many passes until reached the German army, each pass the message Security degree product.
And for the whole plan, only if the information of n is safe to reach the German hands through the intelligence net, there is no suspicion, it is successful. So the degree of reliability of the plan is the product of the security of all messages.
Obviously, the reliability of the plan depends on how these messages are passed through the intelligence.
I need a solution to determine which people the message should be delivered to, and make the final plan the most reliable.

You can use the computer to get the most reliable message delivery scenario.

Input

The first line consists of two integers n and k, the total number of spies and the number of messages that the plan contains.
The second line includes the number of 2N, the first n number is real AS1, AS2, ..., ASN (within [0, 1]), and the number of post n is integer AM1, AM1, ..., AMN.
The third line contains N integers, where I (i = 1, 2, ..., N) integer if 0 means that spy I does not contact the German Intelligence department, and if 1 means that the spy is in contact with the German Intelligence department.
Beginning with row four, each line consists of 4 numbers, followed by: positive integers representing the spy number I and J, security parameters of the spy I and J (real numbers in the range of [0,1]), and the maximum number of messages passed between I and J (I is less than J for each line).
The last line contains two integers-1-1, which indicates the end of the input data.
0

Output

Only one row. This line contains a real number p, giving the entire plan a reliability of P, which retains 5 digits (rounded).
If the intelligence can not pass the K message to the Germans, then the reliability of the plan is 0.
(You can assume that if the plan exists, then it's more reliable than 1e-12)

Sample Input6 13
0.9 0.7 0.8 0 0 0 2 6 8 0 0 0
0 0 0 1 0 1
1 4 0.5 2
2 3 0.9 5
2 5 0.8 2
2 6 0.8 7
3 5 0.8 2
5 6 0.8 4
-1-1


Sample Output0.00021184because it is a tiring ride, the cost of the side is changed to log. 5 digits valid number a bit of a pit ... Look at someone else's code.
#include <iostream>#include<vector>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<map>#include<Set>#include<string>#include<queue>#include<stack>#include<bitset>using namespacestd;#definePB (x) push_back (x)#definell Long Long#defineMK (x, y) make_pair (x, y)#defineLson L, M, rt<<1#defineMem (a) memset (a, 0, sizeof (a))#defineRson m+1, R, rt<<1|1#defineMem1 (a) memset (a,-1, sizeof (a))#defineMEM2 (a) memset (a, 0x3f, sizeof (a))#defineRep (i, N, a) for (int i = A; i<n; i++)#defineFi first#defineSe Secondtypedef pair<int,int>PLL;Const DoublePI = ACOs (-1.0);Const DoubleEPS = 1e-6;Const intMoD = 1e9+7;Const intINF =1061109567;Const intdir[][2] = { {-1,0}, {1,0}, {0, -1}, {0,1} };Const intMAXN = 2e5+5;intNum, head[maxn*2], S, T, N, K, nn, flow, CNT, CAP[MAXN], Q[MAXN], CUR[MAXN], VIS[MAXN];DoubleCost , DIS[MAXN];structnode{intto, Nextt, C; DoubleW; Node () {} node (intTo,intNextt,intCDoubleW): To, Nextt (NEXTT), C (c), W (w) {}}E[MAXN*2];intSPFA () {intSt, Ed; St= ed =0;  for(inti =1; i<maxn; i++) Dis[i]= -inf; ++CNT; Dis[s]=0; Cap[s]=inf; Cur[s]= -1; Q[ed++] =s;  while(st<ed) {        intU = q[st++]; Vis[u]= cnt-1;  for(inti = Head[u]; ~i; i =e[i].nextt) {            intv = e[i].to, C =e[i].c; DoubleW =E[I].W; if(c && dis[v]<dis[u]+w&&fabs (dis[v]-dis[u]-w) >EPS) {Dis[v]= dis[u]+W; CAP[V]=min (c, cap[u]); CUR[V]=i; if(Vis[v]! =CNT) {Vis[v]=CNT; Q[ed++] =v; }            }        }    }    if(Fabs (Dis[t] + inf) <EPS)return 0; Cost+ = dis[t]*Cap[t]; Flow+=Cap[t];  for(inti = cur[t]; ~i; i = cur[e[i^1].to]) {e[i].c-=Cap[t]; E[i^1].C + =Cap[t]; }    return 1;}DoubleMCMF () {Flow= Cost =0;  while(SPFA ()); returnCost ;}voidAddintUintVintCDoubleval) {E[num]= Node (v, Head[u], C, Val); Head[u] = num++; E[num]= Node (u, Head[v],0,-val); HEAD[V] = num++;}voidinit () {mem1 (head); Num= CNT =0; Mem (VIS);}DoubleA[MAXN];voidDealDoubleans) {    Charch[ +]; sprintf (CH,"%.15f\n", ans); intsum=0, I;  for(i=0; sum<5; i++)    {        if((ch[i]!='0'&&ch[i]!='.') |sum>0) Sum++; }    if(ch[i]>='5') Ch[i-1]++; Ch[i]=0;  for(; i>=0; i--)    {        if(ch[i]=='.') Break; Else if(ch[i]>'9') {Ch[i-1]++,ch[i]='0'; }} printf ("%s\n", ch);}intMain () {init (); intN, M, SS, X; CIN>>n>>m; S=0, SS = n+1, t = n+2; Add (S, SS, M, log (1.0));  for(inti =1; i<=n; i++) {scanf ("%LF", &A[i]); }     for(inti =1; i<=n; i++) {scanf ("%d", &x); if(x) {Add (ss, I, X, log (a[i])); }    }     for(inti =1; i<=n; i++) {scanf ("%d", &x); if(x) Add (I, T, M, log (1.0)); }    inty, y1; DoubleX1;  while(SCANF ("%d%d", &x, &y)) {if(x==-1&&y==-1)             Break; scanf ("%lf%d", &x1, &y1);        Add (x, y, y1, log (x1));    Add (y, x, y1, log (x1)); }    DoubleAns =MCMF (); if(flow!=m) {puts ("0.0000\n"); return 0; } Else{ans=exp (ANS);    Deal (ANS); }    return 0;}

Bzoj 2542: [Ctsc2001] Ultimate Intelligence stream fee flow

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.