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. python代码中pass的用法

    我们有时会在方法中写一些注释代码,用来提示这个方法是干嘛的之类,看下面代码: class Game_object: def __init__(self, name): self.name = name ...

  2. Data Structure(3)——软考阶段学习小结

    数据结构计算机等级考试中有,自考中有,软考中同样有,可见其内容的重要程度,今天对软考阶段视频学习内容的总结,同样是对前面学习内容的回顾,同样是对后面学习的铺垫. 中结:原本因为之前有过类似的总结,这次 ...

  3. @property和@synthesize

    main.m #import <Foundation/Foundation.h> #import "Student.h" int main(int argc, cons ...

  4. 引用jquery框架后出错

    问题描述:当引用了jquery框架后,页面的js不能正常工作. 后面我的解决办法:是因为在引用 jquery的框架时的代码为 <script type="text/javascript ...

  5. Matlab工程

    1.matlab设置默认路径 在原来的默认路径(bin)下创建一个名为startup.m的文件,内容为相对路径 cd ..\..\WorkSpace\ 或绝对路径 cd F:\Program\MATL ...

  6. leetcode Binary Tree Paths python

    # Definition for a binary tree node. # class TreeNode(object): # def __init__(self, x): # self.val = ...

  7. QF——UI之UIViewController

    程序一经启动,AppDelegate的实例就会创建一个充满屏幕的window,它是App唯一的,一个App对应一个window.window是UIWindow类型的,继承于UIView,是种特殊的UI ...

  8. Android 三星手机不能调起应用市场

    Uri uri; if (hasAnyMarketInstalled(getContext())) { uri = Uri.parse("market://details?id=" ...

  9. getActionBar().setTitle(); Java.lang.NullPoint异常解决方案

    getActionBar().setTitle(); Java.lang.NullPoint异常解决方案,是由于低版本不支持直接获取的缘故,修改方案: try changing your theme ...

  10. 解析:用 CSS3 和 JavaScript 制作径向动画菜单

    原作者的解析(英文):http://creative-punch.net/2014/02/making-animated-radial-menu-css3-javascript/ 原作者的解析(译文) ...