-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtonghua.cpp
76 lines (75 loc) · 1.5 KB
/
tonghua.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include<cstdio>
#include<queue>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
struct node
{
int fx,fy,next;
double vl;
}st[100022];
int vis[10011],head[100011],n,m,num;
double dis[10011];
void DFS()
{
queue <int> q;
int i,j,ka;
double ans;
memset(vis,0,sizeof(vis));
memset(dis,0,sizeof(dis));
dis[1] = 1.0;
vis[1] = 1;
q.push(1);
while(!q.empty())
{
int pl = q.front();
q.pop();
vis[pl] = 0; // ????
for(int i = head[pl] ; i != -1 ; i = st[i].next)
{
cout<<i<<endl;
int py = st[i].fy;
if(dis[py] < dis[pl] * st[i].vl)
{
dis[py] = dis[pl] * st[i].vl;
if(!vis[py])
{
vis[py] = 1; // ????
q.push(py);
}
}
cout<<dis[py]<<endl;
}
}
printf("%.6lf\n",dis[n] * 100);
}
void add(int px,int py,double va)
{
st[num].fx = px;
st[num].fy = py;
st[num].vl = va;
st[num].next = head[px];
head[px] = num++;
}
int main()
{
int T,a,b,i,j;
double val;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
num = 0 ;
memset(head,-1,sizeof(head));
while(m--)
{
scanf("%d%d%lf",&a,&b,&val);
val /= 100;
add(a,b,val);
add(b,a,val);
}
DFS();
}
return 0;
}