floyd...求最短路时顺便求出路径数. 时间复杂度O(N^3)

-------------------------------------------------------------------------------------------

#include<cstdio>
#include<algorithm>
#include<cstring>
 
using namespace std;
 
typedef long long ll;
 
const int maxn = 109;
const int INF = 0X3F3F3F3F;
 
int N, d[maxn][maxn];
ll cnt[maxn][maxn];
 
int main() {
int m;
scanf("%d%d", &N, &m);
for(int i = 0; i < N; i++) {
for(int j = 0; j < N; j++)
d[i][j] = INF, cnt[i][j] = 0;
d[i][i] = 1;
cnt[i][i] = 1;
}
while(m--) {
int u, v, w;
scanf("%d%d%d", &u, &v, &w);
u--, v--;
d[u][v] = d[v][u] = w;
cnt[u][v] = cnt[v][u] = 1;
}
for(int k = 0; k < N; k++)
for(int i = 0; i < N; i++)
for(int j = 0; j < N; j++)
if(d[i][k] + d[k][j] < d[i][j]) {
d[i][j] = d[i][k] + d[k][j];
cnt[i][j] = cnt[i][k] * cnt[k][j];
} else if(d[i][k] + d[k][j] == d[i][j])
cnt[i][j] += cnt[i][k] * cnt[k][j];
for(int k = 0; k < N; k++) {
double ans = 0;
for(int i = 0; i < N; i++)
for(int j = 0; j < N; j++) if(d[i][j] != INF)
if(d[i][k] + d[j][k] == d[i][j])
ans += (double) cnt[i][k] * cnt[j][k] / cnt[i][j];
printf("%.3lf\n", ans);
}
return 0;
}

-------------------------------------------------------------------------------------------

1491: [NOI2007]社交网络

Time Limit: 10 Sec  Memory Limit: 64 MB
Submit: 1271  Solved: 727
[Submit][Status][Discuss]

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

Source

BZOJ 1491: [NOI2007]社交网络( floyd )的更多相关文章

  1. BZOJ 1491 [NOI2007]社交网络

    1491: [NOI2007]社交网络 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 1159  Solved: 660[Submit][Status] ...

  2. BZOJ 1491: [NOI2007]社交网络(Floyd+暴力乱搞)

    题面: https://www.lydsy.com/JudgeOnline/problem.php?id=1491 题解: 先看数据范围,n<=100..欸可以乱搞了 首先因为小学学过的乘法原理 ...

  3. 1491: [NOI2007]社交网络

    1491: [NOI2007]社交网络 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 881  Solved: 518[Submit][Status] ...

  4. [BZOJ1491][NOI2007]社交网络 floyd

    1491: [NOI2007]社交网络 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 2196  Solved: 1170[Submit][Status ...

  5. BZOJ1491:1491: [NOI2007]社交网络

    1491: [NOI2007]社交网络 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 2204  Solved: 1175[Submit][Status ...

  6. 【BZOJ1491】[NOI2007]社交网络 Floyd

    [BZOJ1491][NOI2007]社交网络 Description 在社交网络(socialnetwork)的研究中,我们常常使用图论概念去解释一些社会现象.不妨看这样的一个问题. 在一个社交圈子 ...

  7. 【BZOJ】1491: [NOI2007]社交网络(floyd)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1491 囧囧囧...................... 囧1:虽然自己想到做法了,但是操作的时候, ...

  8. 1491: [NOI2007]社交网络 - BZOJ

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

  9. 1491. [NOI2007]社交网络【最短路计数】

    Description 在社交网络(socialnetwork)的研究中,我们常常使用图论概念去解释一些社会现象.不妨看这样的一个问题. 在一个社交圈子里有n个人,人与人之间有不同程度的关系.我们将这 ...

随机推荐

  1. 轻松实现语音识别的完整代码在android开发中

    苹果的iphone 有语音识别用的是Google 的技术,做为Google 力推的Android 自然会将其核心技术往Android 系统里面植入,并结合google 的云端技术将其发扬光大. * C ...

  2. wamp 虚拟目录的设置(转载)

    现在先来配置虚拟主机:1.先打开apache的配置文件httpd.conf,并去掉#Include conf/extra/httpd-vhosts.conf前面的#!!2.打开apache的apach ...

  3. 【整理】Ajax异步实现的几种方式总结

    AJAX = Asynchronous JavaScript and XML(异步的 JavaScript 和 XML)AJAX 是一种在无需重新加载整个网页的情况下,能够更新部分网页的技术.GET ...

  4. Struts2配置问题java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter

    方法一:右键点击项目--->build path-->configure build path-->左侧菜单栏就会看到Deployment Assembly-->右侧点击add ...

  5. poj1995-快速幂取模

    #include<iostream> #define LL long long using namespace std; //快速幂算法 LL pow(LL a,LL b,int m){ ...

  6. [转载]PDO防注入原理分析以及使用PDO的注意事项

    本文全部内容转载自月影无痕的博客http://zhangxugg-163-com.iteye.com/blog/1835721#bc2346092,感谢作者的分享 合理正确使用PDO,可以基本上防止S ...

  7. Windows 7/Vista 开机自动登录

    “Win”+“R”打开命令窗口,输入"control userpasswords2"(不包括引号),或者 “rundll32 netplwiz.dll,UsersRunDll” 回 ...

  8. hdu 5730 Shell Necklace fft+cdq分治

    题目链接 dp[n] = sigma(a[i]*dp[n-i]), 给出a1.....an, 求dp[n]. n为1e5. 这个式子的形式显然是一个卷积, 所以可以用fft来优化一下, 但是这样也是会 ...

  9. c# 获取移动硬盘信息、监听移动设备的弹出与插入事件

    原文 http://www.cnblogs.com/coolkiss/p/3328825.html 备忘一下改功能,主要通过WMI来实现,对于监听外接设备的弹出和插入事件一开始使用IntPtr Wnd ...

  10. VS中C++代码折叠

    用VS编写C#时,可以用#region name和#endregion,将代码分段,这样可以将代码折叠起来,当类过大,方法过长时,这种方法可以提高阅读效率,是人看着更舒服. 对于C/C++语言,#re ...