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. Select标签 依据value值默认选中 Jquery

    网上找了非常多都是错的,不行的. 以下方法能够的 <script type="text/javascript"> $(document).ready(function( ...

  2. 一个tabBarController管理多个Storyboard

    随着项目的业务逻辑越来越复杂,随着项目越来越大,那么我们Storybard中得控制器就越来越多, 就越来越难以维护.然而使用Storyborad又能更方便的帮助我们做屏幕适配(PS:尤其在6.6+出来 ...

  3. chartControl 饼状图小Demo

    Short Description     The Pie Chart is represented by the Pie3DSeriesView object, which belongs to P ...

  4. DevExpress.XtraCharts.chartControl

    private Dictionary<string, double> chartPieDataDic = new Dictionary<string, double>(); p ...

  5. [Script]EBS里查看模块的版本、文件的版本信息【Z】

    系统版本信息 装了哪些模块,以及版本信息 select 'Current Application Release: '||ver||' ('||bug||')' "Description&q ...

  6. 对于windows窗口的标题菜单栏的操作——删除/禁用 最小最大话和关闭

    HWND hand = FindWindow(NULL, "计算器"); int nStyle = GetWindowLong(hand, GWL_STYLE);nStyle &a ...

  7. lightoj 1079 Just another Robbery

    题意:给出银行的个数和被抓概率上限.在给出每个银行的钱和抢劫这个银行被抓的概率.求不超过被抓概率上线能抢劫到最多的钱. dp题,转移方程 dp[i][j] = min(dp[i-1][j] , dp[ ...

  8. 关于 MyBatis MyBatis-Spring Jdbc 批量插入的各种比较分析

    因为目前SME项目中编写了一套蜘蛛爬虫程序,所以导致插入数据库的数据量剧增.就项目中使用到的3种DB插入方式进行了一个Demo分析: 具体代码如下: 1: MyBatis 开启Batch方式,最普通的 ...

  9. php传参方式1--ajax

    AJAX即“Asynchronous Javascript And XML”(异步JavaScript和XML),是指一种创建交互式网页应用的网页开发技术. AJAX = 异步 JavaScript和 ...

  10. linux命令学习02-通过tomcat学习ps和netstat

    问题:如何查找tomcat进程,以及tomcat占用的端口号? 1.ps -ef|grep tomcat root 1984 1 19 10:20 ? 00:00:10 /opt/jdk1.7.0_8 ...