BZOJ1491 [NOI2007] Social network

Source: Internet
Author: User

Konjac Konjac is the No. 500 AC of the question 233

Yarn, at one glance it looks very high-end, there is a complex formula ...

Later found ... Is... Floyd Water Problem

D[I][J] represents the shortest distance between I, J, Cnt[i][j] represents the shortest distance between I and J

Then use the multiplication principle to update cnt[i][j] can

1 /**************************************************************2 problem:14913 User:rausen4 language:c++5 result:accepted6 time:104 Ms7 memory:936 KB8 ****************************************************************/9  Ten#include <cstdio> One#include <cstring> A   - using namespacestd; -typedefLong Longll; thetypedefDoubleLF; - Const intN = the; -   - intN, M; + intD[n][n]; - ll Cnt[n][n]; + lf ans; A   atInlineintRead () { -     intx =0, SGN =1; -     CharCH =GetChar (); -      while(Ch <'0'||'9'<ch) { -         if(ch = ='-') SGN =-1; -CH =GetChar (); in     } -      while('0'<= CH && Ch <='9') { tox = x *Ten+ CH-'0'; +CH =GetChar (); -     } the     returnSGN *x; * } $  Panax Notoginseng intMain () { -     intI, J, K, X, Y, Z; then = Read (), M =read (); +memset (D,127/3,sizeof(d)); A      for(i =1; I <= m; ++i) { thex = Read (), y = read (), z =read (); +D[x][y] = d[y][x] =Z; -Cnt[x][y] = cnt[y][x] =1; $     } $      for(k =1; K <= N; ++k) -          for(i =1; I <= N; ++i)if(I! =k) -              for(j =1; J <= N; ++J)if(J! = i && J! =k) the                 if(D[i][j] > D[i][k] +D[k][j]) -D[I][J] = D[i][k] +D[k][j],WuyiCNT[I][J] = cnt[i][k] *Cnt[k][j]; the                 Else if(D[i][j] = = D[i][k] +D[k][j]) -CNT[I][J] + = cnt[i][k] *Cnt[k][j]; Wu      for(k =1; K <= N; ++k) { -Ans =0; About          for(i =1; I <= N; ++i)if(I! =k) $              for(j =1; J <= N; ++J)if(J! = i && J! =k) -                 if(D[i][j] = = D[i][k] +D[k][j]) -Ans + = (LF) (cnt[i][k] * cnt[k][j])/Cnt[i][j]; -printf"%.3lf\n", ans); A     } +     return 0; the}
View Code

BZOJ1491 [NOI2007] Social network

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.