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) { ; ; ...
随机推荐
- 2017年10月31日结束Outlook 2007与Office 365的连接
2017 年10月31日 ,微软即将推出 Office 365中Exchange Online邮箱将需要Outlook for Windows的连接,即通过HTTP Over MAPI方式,传统使用R ...
- python 输出奇偶数并排序
random_numbers = [] for i in range(40): random_numbers.append(random.randint(1, 100)) num1 = [] num2 ...
- PHP使用MySQL报no such file or directory
原因是没有连接数据库.加上下面代码: $link = mysql_connect(DB_HOST,DB_USER,DB_PWD);mysql_select_db(DB_NAME) or die('Co ...
- mysql在控制台里出现中文问号问题
由于重装了wampserver,之前遇到的问题统统会重新出现,那么今天遇到的是在mysql控制台中,在表里输入中文数据,却出现问号的问题: 那么这个就跟编码有关系了,那么,我们就去wampserver ...
- VUE在页面没加载完的时候会显示原代码的处理方法
CSS: [v-cloak] { display: none; } HTML : <div v-cloak> {{ message }} </div> 其中 v-cloak官方 ...
- 经典的hash函数
unsigned int SDBMHash(char *str){ unsigned int hash = 0; while (*str) { // equivale ...
- ios 逆向工程文档汇总
iOS逆向工程工具集 http://www.jianshu.com/p/7f9511d48e05 移动App入侵与逆向破解技术-iOS篇 http://blog.csdn.net/heiby/arti ...
- [Linux发行版] 常见Linux系统下载(转)
本专题页汇总最受欢迎的Linux发行版基本介绍和下载地址,如果您是一位刚接触Linux的新手,这里的介绍可能对您有所帮助,如果您是以为Linux使用前辈,也可以在评论处留下您宝贵意见和经验,以便让更多 ...
- next_permutation暴力搜索,POJ(3187)
题目链接:http://poj.org/problem?id=3187 解题报告: #include <stdio.h> #include <iostream> #includ ...
- object dection资源
https://handong1587.github.io/deep_learning/2015/10/09/object-detection.html