TopCoder SRM 710 Div2 Hard MinMaxMax Floyd最短路变形
题意:
有一个无向连通图,没有重边没有自环,并给出顶点的权值和边的权值
定义一条路径\(difficulty\)值为该路径上最大的点权乘上最大的边权
定义函数\(d(i,j)\)为\(i,j\)之间的所有中路径最小的\(difficulty\)值
求\(\sum_{i<j}d(i,j)\)
分析:
令\(minw(i,j)\)表示\(i,j\)之间的路径中最大边权的最小值
按照点权从小到大枚举点\(k\),然后按照Floyd算法那样逐个去更新:
\]
\]
#define REP(i, a, b) for(int i = a; i < b; i++)
#define SZ(a) ((int)a.size())
#define ALL(a) a.begin(), a.end()
typedef long long LL;
const LL INF = 1LL << 60;
typedef pair<int, int> PII;
const int maxn = 300 + 10;
LL minw[maxn][maxn], ans[maxn][maxn];
vector<PII> vertex;
class MinMaxMax {
public:
long long findMin(vector<int> a, vector<int> b, vector<int> w, vector<int> v) {
int n = SZ(v), m = SZ(a);
REP(i, 0, n) REP(j, 0, n) minw[i][j] = ans[i][j] = INF;
REP(i, 0, m) minw[a[i]][b[i]] = minw[b[i]][a[i]] = w[i];
REP(i, 0, n) vertex.emplace_back(v[i], i);
sort(ALL(vertex));
for(PII x : vertex) {
int k = x.second;
REP(i, 0, n) REP(j, 0, n) if(i != j) {
minw[i][j] = min(minw[i][j], max(minw[i][k], minw[k][j]));
if(minw[i][j] == INF) continue;
ans[i][j] = min(ans[i][j], minw[i][j] * max(v[i], max(v[j], v[k])));
}
}
LL res = 0;
REP(i, 0, n) REP(j, 0, i) res += ans[i][j];
return res;
}
};
TopCoder SRM 710 Div2 Hard MinMaxMax Floyd最短路变形的更多相关文章
- Topcoder Srm 673 Div2 1000 BearPermutations2
\(>Topcoder \space Srm \space 673 \space Div2 \space 1000 \space BearPermutations2<\) 题目大意 : 对 ...
- Topcoder Srm 671 Div2 1000 BearDestroysDiv2
\(>Topcoder \space Srm \space 671 \space Div2 \space 1000 \space BearDestroysDiv2<\) 题目大意 : 有一 ...
- 求拓扑排序的数量,例题 topcoder srm 654 div2 500
周赛时遇到的一道比较有意思的题目: Problem Statement There are N rooms in Maki's new house. The rooms are number ...
- Topcoder srm 632 div2
脑洞太大,简单东西就是想复杂,活该一直DIV2; A:水,基本判断A[I]<=A[I-1],ANS++; B:不知道别人怎么做的,我的是100*N*N;没办法想的太多了,忘记是连续的数列 我们枚 ...
- topcoder SRM 628 DIV2 BracketExpressions
先用dfs搜索所有的情况,然后判断每种情况是不是括号匹配 #include <vector> #include <string> #include <list> # ...
- topcoder SRM 628 DIV2 BishopMove
题目比较简单. 注意看测试用例2,给的提示 Please note that this is the largest possible return value: whenever there is ...
- Topcoder SRM 683 Div2 B
贪心的题,从左向右推过去即可 #include <vector> #include <list> #include <map> #include <set&g ...
- Topcoder SRM 683 Div2 - C
树形Dp的题,根据题意建树. DP[i][0] 表示以i为根节点的树的包含i的时候的所有状态点数的总和 Dp[i][1] 表示包含i结点的状态数目 对于一个子节点v Dp[i][0] = (Dp[v] ...
- Topcoder SRM 626 DIV2 SumOfPower
本题就是求所有连续子数列的和 开始拿到题目还以为求的时数列子集的和,认真看到题目才知道是连续子数列 循环遍历即可 int findSum(vector <int> array) { ; ; ...
随机推荐
- rpm打包工具
http://fedoraproject.org/wiki/How_to_create_an_RPM_package # rpm --showrc|grep _topdir -14: _builddi ...
- python3基础14(有关日期的使用2)
#!/usr/bin/env python# -*- coding:utf-8 -*-import timeimport datetime,shutil,osimport calendar print ...
- gitlab安装详解
官方网站---https://www.gitlab.com.cn/downloads/ 1.选择操作系统 例如:CentOS6.CentOS7.Ubuntu12.04.Ubuntu14.04等,选择相 ...
- Microsoft EDP(enterprise database protection)配置策略中的三种Rule template
搭建Microsoft EDP环境: Microsoft 10 insider preview,Microsoft Intune,ie10(要安装插件silverlight) 这里暂时只说在进行配置策 ...
- js 流程控制语句
1.复合语句 2.switch语句 3.do...while语句 4.while语句 5.for语句 6.for...in语句 7.break和continue语句 9.with语句 10.if语句 ...
- IOS 纯代码添加 Button Image Label 添加到自定义View中
@interface ViewController () /**获取.plist数据*/ @property (nonatomic,strong) NSArray *apps; @end @imple ...
- 2018.8.5 Bootstrap 使用
Bootstrap的环境搭建 <link rel="stylesheet" type="text/css" href="css/bootstra ...
- 改Chrome的User Agent,移动版网络
理论上访问手机版或者iPad等平板电脑版的网络,应该可以剩些流量的,毕竟移动网络是经过优化压缩的,但是PC电脑如果访问移动版的网站呢?我主要使用的浏览器是Chrome,这几天也找了下Chrome下的修 ...
- 第20章 USART—串口通讯—零死角玩转STM32-F429系列
第20章 USART—串口通讯 全套200集视频教程和1000页PDF教程请到秉火论坛下载:www.firebbs.cn 野火视频教程优酷观看网址:http://i.youku.com/fi ...
- python中的zipfile
zipfile - Work with ZIP archives ZipFile.namelist() Return a list of archive members by name. 返回压缩成员 ...