Acdream-chasing girl

Source: Internet
Author: User

Start with the question:

Chasing girl Time limit:2000/1000 ms (Java/Others) Memory limit:128000/64000 KB (Java/others) submitstatusproblem description

Yys is a well-known master in scau_acm, and he was admired by friends and family for representing scau in world final. However, yys has another hobby: getting a girl. In college, he often went to various girlfriends to play, but on the road he encountered the scum that worships him all day, which made him very worried. As a result, every time he goes to his girlfriend, he wants to avoid the scum that worships him.
Yys abstracts the campus into N points and M bidirectional roads. From many experiences, he counts the probability of encountering slag on a certain road. Now he wants to go from A to B. He wants to select the shortest length because he is eager to contact his girlfriend XXX, on this basis, the path with the minimum slag probability is met. Yys only cares about his girlfriend. He wants to help him calculate the shortest path length and minimum probability.

 

 

Input

The first line is an integer T, indicating the number of test data groups.
For each group of data,
First line, two integers n, m
In the next M line, each line has four integers U, V, W, P, which indicates that there is a two-way W path between u and v. The probability of encountering slag on this road is P %
Last line, two integers A and B

Data range:
1 <= T <= 100
1 <= n <= 1000
1 <= m <= 10000
1 <= U, V, a, B <= N
1 <= W <= 100
0 <= P <100

The data must have no duplicate edges, no self-loops, and at least one path exists between A and B.

 

 

Output

For each group of data, the minimum path length and minimum probability are output (6 decimal places are retained ).

 

Sample Input
24 41 2 1 502 3 2 501 4 5 204 3 3 302 44 41 2 1 502 3 2 501 4 4 204 3 3 302 4
Sample output
5 0.6500005 0.600000

The simplest and most short-circuited path is to calculate the minimum short-circuited path, and calculate the probability that the person will not be met along the way. If the distance to be modified is equal to the obtained shortest path, it is determined based on the probability. If the probability increases, it is updated to the new probability.
The result is obtained after the probability is reduced by 1 (1-the probability of the opposite side ).
The figure here has a ring. Looking at my notes, it seems that dij can only find the Dag, and spfa is used, but the friends say that dij is used too ······

Code:

 1 /* 2 * this code is made by sineatos 3 * Problem: 1180 4 * Verdict: Accepted 5 * Submission Date: 2014-07-31 15:23:49 6 * Time: 228MS 7 * Memory: 1884KB 8 */ 9 #include <cstdio>10 #include <cstring>11 #include <algorithm>12 #include <queue>13 #include <vector>14 #define MAX 1000215 #define INF (1<<30)16 #define ll long long17 using namespace std;18  19 int n,m,st,ed;20  21 typedef struct{22     int to,next,l;23     double p;24 }edge;25  26 edge e[MAX<<1];27 int p[MAX],tot;28 int dist[MAX];29 double pa[MAX];30 queue<int> q;31 bool vis[MAX];32  33 inline void add(int u,int v,int l,int per){34     e[tot].to=v; e[tot].l=l; e[tot].p=1-(per*1.0/100); e[tot].next=p[u]; p[u]=tot++;35 }36  37 void spfa(){38     for(int i=1;i<=n;i++) dist[i]=INF;39     memset(vis,0,sizeof(vis));40     while(!q.empty()) q.pop();41     dist[st]=0;42     pa[st]=1;43     vis[st]=1;44     q.push(st);45     while(!q.empty()){46         int u = q.front();47         q.pop();48         vis[u]=0;49         for(int i=p[u];i!=-1;i=e[i].next){50             if(e[i].l+dist[u]<dist[e[i].to]){51                 dist[e[i].to]=e[i].l+dist[u];52                 pa[e[i].to]=pa[u]*e[i].p;53                 if(!vis[e[i].to]){54                     vis[e[i].to]=1;55                     q.push(e[i].to);56                 }57             }else if(e[i].l+dist[u]==dist[e[i].to] && pa[e[i].to]<pa[u]*e[i].p){58                 pa[e[i].to]=pa[u]*e[i].p;59                 if(!vis[e[i].to]){60                     vis[e[i].to]=1;61                     q.push(e[i].to);62                 }63             }64         }65     }66 }67  68 int main()69 {70     int t,u,v,l,per;71     //freopen("data.txt","r",stdin);72     scanf("%d",&t);73     while(t--){74         scanf("%d %d",&n,&m);75         memset(p,-1,sizeof(p));76         tot=0;77         for(int i=0;i<m;i++){78             scanf("%d %d %d %d",&u,&v,&l,&per);79             add(u,v,l,per);80             add(v,u,l,per);81         }82         scanf("%d %d",&st,&ed);83         spfa();84         printf("%d %.6lf\n",dist[ed],1-pa[ed]);85     }86     return 0;87 }
/* Chasing girl */

 

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.