BZOJ1491: [NOI2007] Social network

Source: Internet
Author: User

Transmission Door

The shortest-circuit count problem. Because the amount of data is very small ($N \leq 100$), so Floyd do it casually.

$f [i][j]$ represents the path length, $g [i][j]$ represents the maximum number of short-circuit scenarios.

Run the bare Floyd first, then use the multiplication principle to count the $g[i][j]$.

$g [i][j]=\sum g[i][k] \times g[k][j]$

Bzoj 1491//by cydiater//2016.10.27#include <iostream> #include <cstdlib> #include <cstdio># Include <queue> #include <map> #include <ctime> #include <cmath> #include <cstring># Include <string> #include <algorithm> #include <bitset> #include <iomanip>using namespace std;# Define ll long long#define up (i,j,n) for (int. i=j;i<=n;i++) #define DOWN (i,j,n) for (int i=j;i>=n;i--) #define CMAX (A, b) A=max (A, a) #define Cmin (A, B) A=min (A, B) #define DB Doubleconst ll Maxn=105;const ll Oo=1ll<<60;inline ll read () {CH Ar Ch=getchar (); ll X=0,f=1;while (ch> ' 9 ' | | ch< ' 0 ') {if (ch== '-') F=-1;ch=getchar ();} while (ch>= ' 0 ' &&ch<= ' 9 ') {x=x*10+ch-' 0 '; Ch=getchar ();} return x*f;} ll n,m,f[maxn][maxn],g[maxn][maxn],len=0;db ans[maxn];struct edge{ll x,y,v;} E[maxn*maxn];namespace solution{void init () {n=read (); M=read (); Up (i,1,n) up (j,1,n) f[i][j]=oo;up (i,1,n) F[i][i]=0;memset (G,0,sizeof (g)); up (i,1,m) {ll x=read (), Y=read (), V =read (); F[x][y]=f[y][x]=v;e[++len]= (Edge) {x,y,v};}} void Slove () {Up (k,1,n) up (i,1,n) up (j,1,n) cmin (F[i][j],f[i][k]+f[k][j]), up (I,1,len) {ll x=e[i].x,y=e[i].y,v=e[i].v; if (f[x][y]==v) g[x][y]=g[y][x]=1;} Up (K,1,n) up (i,1,n) up (j,1,n) if (f[i][j]==f[i][k]+f[k][j]&&i!=k&&j!=k) {g[i][j]+=g[i][k]*g[k][j];/ /cout<<i<< ' <<k<< ' <<j<< ' <<g[i][k]<< ' <<g[k][j]<< "' <<g[i][j]<<endl;} Up (K,1,n) up (i,1,n) up (j,1,n) if (f[i][j]==f[i][k]+f[k][j]&&i!=k&&k!=j&&i!=j) ans[k]+= (db) ( G[I][K]*G[K][J])/(DB) (G[i][j]);} void output () {Up (i,1,n) printf ("%.3lf\n", Ans[i]);}} int main () {//freopen ("input.in", "R", stdin), using namespace Solution;init (); slove (); output (); return 0;}

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.