Informatics Olympiad: [1345] Sweet Butter

Why is this happening... For the first time, there is a question that can AC...

Violently opening the array will not work, Dijkstra will explode the time if you do it directly.

Then use the heap optimization, the result is not done with the adjacency list, resulting in a burst of time...

(It would be better to analyze it earlier (without the adjacency list, it will definitely explode the time, ah hey)

Then, in fact, thinking about it like this is also a water problem, so just spend money to buy a lesson. .

 1 #include<bits/stdc++.h> 
 2 using namespace std;
 3 
 4 //感觉还是Dijkstra 
 5 const int maxx = 2050;
 6 const double Inf = 1e10;
 7 double mon[maxx];
 8 int jud[maxx],p[maxx][maxx];
 9 
10 
11 int main()
12 {
13 //    FILE *f = fopen("data.txt","r");
14     int i,j,k,n,m,x,y,a,b,t,temp,z;
15     double minn;
16     scanf("%d%d",&n,&m);
17 //    fscanf(f,"%d%d",&n,&m);
18     for(i=1;i<=n;i++)
19         mon[i] = Inf;
20     
21     for(i=1;i<=m;i++)
22     {
23         scanf("%d%d%d",&x,&y,&z);
24 //        fscanf(f,"%d%d%d",&x,&y,&z);
25         p[x][y] = p[y][x] = z;
26     }
27     
28     scanf("%d%d",&a,&b);
29 //    fscanf(f,"%d%d",&a,&b);
30     t = b;
31     mon[t] = 100;
32     for(i=1;i<=n;j++)
33     {
34         temp = 0;
35         minn = Inf;
36         jud[t] = 1;
37         for(j=1;j<=n;j++)
38             if(p[t][j] && !jud[j])    mon[j] = min(mon[j],mon[t] /(1.0-p[t][j]/100.0));
39             
40         for(k=1;k<=n;k++)
41             if(!jud[k] && mon[k]<minn )
42             {
43                 minn = mon[k];
44                 temp = k;
45             }
46         if(!temp) break;
47         t = temp;
48     }
49     printf("%.8f",mon[a]);
50     return 0;
51 }
1345

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325285669&siteId=291194637