[CF773D]Perishable Roads
[CF773D]Perishable Roads
题目大意:
一个\(n(n\le2000)\)个点的完全图\(G\),定义\(d(x)\)为生成树上点\(x\)到根路径上的最小边权。问图\(G\)的生成树\(\sum d(x)\)最小是多少?
思路:
由题解得到图的一些性质,然后就不难了。
源代码:
#include<cstdio>
#include<cctype>
#include<climits>
#include<algorithm>
using int64=long long;
inline int getint() {
register char ch;
while(!isdigit(ch=getchar()));
register int x=ch^'0';
while(isdigit(ch=getchar())) x=(((x<<2)+x)<<1)+(ch^'0');
return x;
}
constexpr int N=2001;
bool vis[N];
int w[N][N],d[N];
int main() {
const int n=getint();
int min=INT_MAX;
for(register int i=1;i<=n;i++) {
for(register int j=i+1;j<=n;j++) {
min=std::min(min,w[i][j]=w[j][i]=getint());
}
}
d[0]=INT_MAX;
for(register int i=1;i<=n;i++) {
d[i]=INT_MAX;
for(register int j=1;j<=n;j++) {
if(i==j) continue;
w[i][j]-=min;
d[i]=std::min(d[i],w[i][j]*2);
}
}
for(register int i=1;i<=n;i++) {
int k=0;
for(register int j=1;j<=n;j++) {
if(!vis[j]&&d[j]<d[k]) k=j;
}
vis[k]=true;
for(register int j=1;j<=n;j++) {
d[j]=std::min(d[j],d[k]+w[k][j]);
}
}
for(register int i=1;i<=n;i++) {
printf("%lld\n",(int64)min*(n-1)+d[i]);
}
return 0;
}
[CF773D]Perishable Roads的更多相关文章
- Codeforces 806 D. Perishable Roads Dijkstra
原文链接https://www.cnblogs.com/zhouzhendong/p/CF806D.html 题目传送门 - CF806D 题意 给定一个 n 个点的无向完全图,每一条边有一定的边权. ...
- Codeforces Round#412 Div.2
A. Is it rated? 题面 Is it rated? Here it is. The Ultimate Question of Competitive Programming, Codefo ...
- poj 1251 Jungle Roads (最小生成树)
poj 1251 Jungle Roads (最小生成树) Link: http://poj.org/problem?id=1251 Jungle Roads Time Limit: 1000 ...
- Jungle Roads[HDU1301]
Jungle Roads Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- POJ1947 Rebuilding Roads[树形背包]
Rebuilding Roads Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 11495 Accepted: 5276 ...
- Constructing Roads——F
F. Constructing Roads There are N villages, which are numbered from 1 to N, and you should build som ...
- Constructing Roads In JGShining's Kingdom(HDU1025)(LCS序列的变行)
Constructing Roads In JGShining's Kingdom HDU1025 题目主要理解要用LCS进行求解! 并且一般的求法会超时!!要用二分!!! 最后蛋疼的是输出格式的注 ...
- 【CodeForces 567E】President and Roads(最短路)
Description Berland has n cities, the capital is located in city s, and the historic home town of th ...
- POJ 1947 Rebuilding Roads
树形DP..... Rebuilding Roads Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 8188 Accepted: ...
随机推荐
- npm install 权限的问题
用ctrl+r切换到对象的目录,以管理圆的身份执行 npm cache clean first. If that doesn’t fix things, take a look in %APPDATA ...
- POJ3349 Snowflake Snow Snowflakes (hash
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 48624 Accep ...
- is
MyType a = null; if (a is MyType) == False
- ES6学习笔记(一)——Promise
Promise 是 ES6 提供的一种异步编程的解决方案: 将异步操作以同步操作的流程表达出来,避免了层层嵌套的回调函数(解决异步函数回调地狱的问题).Promise 对象保存着异步操作的结果. 首先 ...
- 【BZOJ3680】吊打xxx [模拟退火]
吊打XXX Time Limit: 10 Sec Memory Limit: 128 MB[Submit][Status][Discuss] Description gty又虐了一场比赛,被虐的蒟蒻 ...
- [Leetcode Week3]Evaluate Division
Evaluate Division题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/evaluate-division/description/ Desc ...
- [ Python - 4 ] python 装饰器
装饰器有很多经典的使用场景,例如插入日志.性能测试.事务处理等等,有了装饰器,就可以提取大量函数中与本身功能无关的类似代码,从而达到代码重用的目的. 装饰器有两种写法: 1. 装饰器不传参数 2. 装 ...
- 快速搭建YUM源和yum使用
yum是一种便捷,快速的RPM包安装方法,可以避免很多包的关联性,但RedHat的YUM源,不是免费的,需要他们的RHN才能够用,而CentOS得yum是免费的,由于CentOS和RedHat相似度高 ...
- python中进程池的应用
#原创,转载请联系 假设我们写的一个程序需要运行100个子进程的时候,那么写程序时,不可能循环创建销毁100个进程吧?进程的创建与销毁是很耗系统的资源的. 进程池的作用就体现出来了. 进程池可以控制进 ...
- delphi dispose释放内存的方法 New 和 GetMem 的区别
来自:http://blog.sina.com.cn/s/blog_4bc47d2301018trf.html -------------------------------------------- ...