1491: [NOI2007]社交网络 - BZOJ

Description


Input


Output
输出文件包括n 行,每行一个实数,精确到小数点后3 位。第i 行的实数表 示结点i 在社交网络中的重要程度。
Sample Input
4 4
1 2 1
2 3 1
3 4 1
4 1 1
Sample Output
1.000
1.000
1.000
1.000
HINT


为1


 

其实floyd已经够了,我这sb没想到,TM想了半天想出一个拓扑排序的,还用了floyd预处理最短路,而且还下了数据和标程才突然想起来,我TM没拓扑排序for个屁啊(最后写出来pascal第一,当然是因为floyd做了太多没用的事啦)

  1 const
  2     maxn=105;
  3     maxm=4520;
  4 var
  5     first,d:array[0..maxn]of longint;
  6     last,next,w:array[0..maxm*2]of longint;
  7     f:array[0..maxn,0..maxn]of longint;
  8     ans,a:array[0..maxn]of double;
  9     s:array[0..maxn]of int64;
 10     n,m,tot:longint;
 11  
 12 procedure insert(x,y,z:longint);
 13 begin
 14     inc(tot);
 15     last[tot]:=y;
 16     next[tot]:=first[x];
 17     first[x]:=tot;
 18     w[tot]:=z;
 19 end;
 20  
 21 var
 22     q:array[0..maxn]of longint;
 23     l,r:longint;
 24  
 25 procedure work(x:longint);
 26 var
 27     i:longint;
 28 begin
 29     for i:=1 to n do s[i]:=0;
 30     for i:=1 to n do a[i]:=0;
 31     for i:=1 to n do d[i]:=0;
 32     for l:=1 to n do
 33         begin
 34             i:=first[l];
 35             while i<>0 do
 36                 begin
 37                     if f[x,l]+w[i]=f[x,last[i]] then inc(d[last[i]]);
 38                     i:=next[i];
 39                 end;
 40         end;
 41     l:=1;r:=1;q[1]:=x;s[x]:=1;
 42     while l<=r do
 43         begin
 44             i:=first[q[l]];
 45             while i<>0 do
 46                 begin
 47                     if f[x,q[l]]+w[i]=f[x,last[i]] then
 48                     begin
 49                         dec(d[last[i]]);
 50                         if d[last[i]]=0 then
 51                         begin
 52                             inc(r);
 53                             q[r]:=last[i];
 54                         end;
 55                         inc(s[last[i]],s[q[l]]);
 56                     end;
 57                     i:=next[i];
 58                 end;
 59             inc(l);
 60         end;
 61     for l:=n downto 2 do
 62         begin
 63             i:=first[q[l]];
 64             while i<>0 do
 65                 begin
 66                     if f[x,q[l]]+w[i]=f[x,last[i]] then a[q[l]]:=a[q[l]]+a[last[i]]+1/s[last[i]];
 67                     i:=next[i];
 68                 end;
 69         end;
 70     for i:=1 to n do ans[i]:=ans[i]+a[i]*s[i];
 71 end;
 72  
 73 procedure main;
 74 var
 75     i,j,k,x,y,z:longint;
 76 begin
 77     read(n,m);
 78     fillchar(f,sizeof(f),1);
 79     for i:=1 to n do f[i,i]:=0;
 80     for i:=1 to m do
 81         begin
 82             read(x,y,z);
 83             insert(x,y,z);
 84             insert(y,x,z);
 85             if z<f[x,y] then
 86             begin
 87                 f[x,y]:=z;
 88                 f[y,x]:=z;
 89             end;
 90         end;
 91     for k:=1 to n do
 92         for i:=1 to n do
 93             for j:=1 to n do
 94                 if f[i,k]+f[k,j]<f[i,j] then f[i,j]:=f[i,k]+f[k,j];
 95     for i:=1 to n do work(i);
 96     for i:=1 to n do writeln(ans[i]:0:3);
 97 end;
 98  
 99 begin
100     main;
101 end.
View Code

 

posted @ 2015-07-23 00:26  Randolph87  阅读(228)  评论(0编辑  收藏  举报