题意:

有一个无向连通图,没有重边没有自环,并给出顶点的权值和边的权值

定义一条路径\(difficulty\)值为该路径上最大的点权乘上最大的边权

定义函数\(d(i,j)\)为\(i,j\)之间的所有中路径最小的\(difficulty\)值

求\(\sum_{i<j}d(i,j)\)

分析:

令\(minw(i,j)\)表示\(i,j\)之间的路径中最大边权的最小值

按照点权从小到大枚举点\(k\),然后按照Floyd算法那样逐个去更新:

\[minw(i,j)=min(minw(i,j), max(minw(i,k), minw(k,j)))
\]

\[d(i,j)=min(d(i,j),minw(i,j) \cdot max(v_i, v_j, v_k))
\]

#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最短路变形的更多相关文章

  1. Topcoder Srm 673 Div2 1000 BearPermutations2

    \(>Topcoder \space Srm \space 673 \space Div2 \space 1000 \space BearPermutations2<\) 题目大意 : 对 ...

  2. Topcoder Srm 671 Div2 1000 BearDestroysDiv2

    \(>Topcoder \space Srm \space 671 \space Div2 \space 1000 \space BearDestroysDiv2<\) 题目大意 : 有一 ...

  3. 求拓扑排序的数量,例题 topcoder srm 654 div2 500

    周赛时遇到的一道比较有意思的题目: Problem Statement      There are N rooms in Maki's new house. The rooms are number ...

  4. Topcoder srm 632 div2

    脑洞太大,简单东西就是想复杂,活该一直DIV2; A:水,基本判断A[I]<=A[I-1],ANS++; B:不知道别人怎么做的,我的是100*N*N;没办法想的太多了,忘记是连续的数列 我们枚 ...

  5. topcoder SRM 628 DIV2 BracketExpressions

    先用dfs搜索所有的情况,然后判断每种情况是不是括号匹配 #include <vector> #include <string> #include <list> # ...

  6. topcoder SRM 628 DIV2 BishopMove

    题目比较简单. 注意看测试用例2,给的提示 Please note that this is the largest possible return value: whenever there is ...

  7. Topcoder SRM 683 Div2 B

    贪心的题,从左向右推过去即可 #include <vector> #include <list> #include <map> #include <set&g ...

  8. Topcoder SRM 683 Div2 - C

    树形Dp的题,根据题意建树. DP[i][0] 表示以i为根节点的树的包含i的时候的所有状态点数的总和 Dp[i][1] 表示包含i结点的状态数目 对于一个子节点v Dp[i][0] = (Dp[v] ...

  9. Topcoder SRM 626 DIV2 SumOfPower

    本题就是求所有连续子数列的和 开始拿到题目还以为求的时数列子集的和,认真看到题目才知道是连续子数列 循环遍历即可 int findSum(vector <int> array) { ; ; ...

随机推荐

  1. ansible使用5-Variables

    变量命名 支持数字.字母.下划线 有效:foo_port, foo5 无效:foo-port, foo port, foo.port, 12 playbook定义 - hosts: webserver ...

  2. java之Socket多线程传递对象

    服务器端利用线程池回复客户端: public class Server implements Runnable { private final ServerSocket server; private ...

  3. ALPS语言学校(西雅图)|ALPS Language School (Seattle)

    http://www.swliuxue.com/school-3879.html 所属国家: 美国 所在省洲: 华盛顿州 所在城市: 华盛顿州 建校时间: 1992年 学校类型: 院校 学校类别: 私 ...

  4. 检测浏览器中是否有Flash插件

    由于IE和非IE浏览器检测方式不同,所以代码如下 function hasPlugin(name){ debugger; name = name.toLowerCase(); for(var i=0; ...

  5. IOS 设置定时器,执行方法

    //设置定时器(1秒后跳到一下题) [self performSelector:@selector(nextQuestion) withObject:nil afterDelay:1.0];

  6. CUDA三维数组

    http://hpcbbs.it168.com/forum.php?mod=viewthread&tid=1643 根据上面链接的帖子研究了下三维数组,就像他自己说的一样是有问题的,我自己修改 ...

  7. 第13章 GPIO-位带操作—零死角玩转STM32-F429系列

    第13章     GPIO—位带操作 全套200集视频教程和1000页PDF教程请到秉火论坛下载:www.firebbs.cn 野火视频教程优酷观看网址:http://i.youku.com/fire ...

  8. C#接口定义

    C#接口定义 C#不支持多重继承,但是客观世界出现多重继承的情况又比较多.为了避免传统的多重继承给程序带来的复杂性等问题,C# 提出了接口的概念.通过接口可以实现多重继承的功能.  继承该接口的类或结 ...

  9. CTS、CLS、CLR分别作何解释?

    CTS.CLS.CLR分别作何解释? 答:CTS:通用类型系统.CLS:通用语言规范.CLR:公共语言运行库.

  10. ES6学习(三):数组的扩展

    chapter08 数组的扩展 8.1 扩展运算符 8.1.1 扩展运算符的含义 ... 如同rest运算符的逆运算,将一个数组转换为用逗号分隔的参数序列. console.log(...[1, 2, ...