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. POJ 2029 DP || 暴力

    在大矩形中找一个小矩形 使小矩形包括的*最多 暴力或者DP  水题 暴力: #include "stdio.h" #include "string.h" int ...

  2. PL/SQL连接oracle数据库

    PL/SQL连接oracle数据库 1.简单介绍 在不安装oracle数据库的情况下使用pl/sql连接远程oracle数据库. 2.详细步骤: a)      安装PL/SQL.依据自己的操作系统安 ...

  3. [iOS]手把手教你实现微信小视频

    本文个人原创,转载请注明出处,谢谢. 前段时间项目要求需要在聊天模块中加入类似微信的小视频功能,这边博客主要是为了总结遇到的问题和解决方法,希望能够对有同样需求的朋友有所帮助. 效果预览: 这里先罗列 ...

  4. BZOJ 3221: [Codechef FEB13] Obserbing the tree树上询问( 可持久化线段树 + 树链剖分 )

    树链剖分+可持久化线段树....这个一眼可以看出来, 因为可持久化所以写了标记永久化(否则就是区间修改的线段树的持久化..不会), 结果就写挂了, T得飞起...和管理员拿数据调后才发现= = 做法: ...

  5. mud目录命令说明

      目錄結構 以下列出的是 ES2 mudlib 根目錄下標準的子目錄結構,以及簡短的說明. /adm 儲存由系統管理者所管理的程式與資料檔. /std 儲存標準物件的程式碼. /obj 儲存通用物件 ...

  6. C# JSON各种查找法

    http://blog.csdn.net/yangxiaojun9238/article/details/8490319

  7. Python中文显示问题

    默认pyhon使用ASCII码来解释程序的,默认不支持中文,需要在程序的第一行或者第二行声明编码. 官方解决方案:https://www.python.org/dev/peps/pep-0263/ T ...

  8. Ubuntu各种软件的安装

    普通的例如g++.deadbeef等源中有的软件,可以用apt-get安装 sudo apt-get install XXX 还有很多直接在software center搜索下载 对于下载来源代码需要 ...

  9. 让两个Div并排显示

    一.使用display的inline属性 <div style="width:300px; height:auto; float:left; display:inline"& ...

  10. J2SE知识点摘记-数据库(一)

    一.          数据库连接 在JDBC的操作过程中,进行数据库连接的主要步骤如下: 通过Class.forName()加载数据库的驱动程序.首先需要利用来自Class类中的静态方法forNam ...