[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的更多相关文章

  1. Codeforces 806 D. Perishable Roads Dijkstra

    原文链接https://www.cnblogs.com/zhouzhendong/p/CF806D.html 题目传送门 - CF806D 题意 给定一个 n 个点的无向完全图,每一条边有一定的边权. ...

  2. Codeforces Round#412 Div.2

    A. Is it rated? 题面 Is it rated? Here it is. The Ultimate Question of Competitive Programming, Codefo ...

  3. poj 1251 Jungle Roads (最小生成树)

    poj   1251  Jungle Roads  (最小生成树) Link: http://poj.org/problem?id=1251 Jungle Roads Time Limit: 1000 ...

  4. Jungle Roads[HDU1301]

    Jungle Roads Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  5. POJ1947 Rebuilding Roads[树形背包]

    Rebuilding Roads Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 11495   Accepted: 5276 ...

  6. Constructing Roads——F

    F. Constructing Roads There are N villages, which are numbered from 1 to N, and you should build som ...

  7. Constructing Roads In JGShining's Kingdom(HDU1025)(LCS序列的变行)

    Constructing Roads In JGShining's Kingdom  HDU1025 题目主要理解要用LCS进行求解! 并且一般的求法会超时!!要用二分!!! 最后蛋疼的是输出格式的注 ...

  8. 【CodeForces 567E】President and Roads(最短路)

    Description Berland has n cities, the capital is located in city s, and the historic home town of th ...

  9. POJ 1947 Rebuilding Roads

    树形DP..... Rebuilding Roads Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 8188 Accepted: ...

随机推荐

  1. 安卓sdk安装教程

    http://blog.csdn.net/love4399/article/details/77164500

  2. codeforces902B. Coloring a Tree

    B. Coloring a Tree 题目链接: https://codeforces.com/contest/902/problem/B 题意:给你一颗树,原先是没有颜色的,需要你给树填色成指定的样 ...

  3. Create a conditional DNS forwarder on our domain.com to Amazon default DNS provider

    Backgroup: I have an AWS Managed Active Directory(domain.com). I created a DHCP options set  to my d ...

  4. 重新认识REST

    大家对REST的认识? 谈到REST大家的第一印象就是通过http协议的GET,POST,DELETE,PUT方法实现对url资源的CRUD(创建.读取.更新和删除)操作.比如http://www.a ...

  5. 密码字典生成工具crunch的简单使用

      案例1: crunch 1 8 #生成最小1位,最大8位,由26个小写字母为元素的所有组合   案例2: crunch 1 6 abcdefg #生成最小为1,最大为6.由abcdefg为元素的所 ...

  6. DDCTF - evil 一个伪装成docx的exe

    0x01 题目描述 题目比较简单,不过这种题感觉比单纯的逆向算法来有意思的多,所以记录一下~ 0x02 脱壳 先拖到IDA瞅一眼,发现加壳了 用PEID查一下是什么壳,但是没有查出来.使用String ...

  7. 创建堆 HeapCreate

    创建额外的堆的原因1.对组件进行保护2.更有效的内存管理3.局部访问4.避免线程同步开销5.快速释放 HeapCreate函数原型:HANDLE WINAPI HeapCreate( _In_ DWO ...

  8. MySQL 查询语句练习1

    1.创建成绩表,字段包括:学生姓名,语文成绩,数学成绩,英语成绩 向表中插入多条数据: 查询: (1) 查询所有学生的数学成绩和总成绩 (2) 查询所有学生的语文和数学成绩和,按从高到低排序 (3) ...

  9. linux 链表实例应用程序【转】

    转自:http://blog.csdn.net/echo_qiang/article/details/6233057 /**************************************** ...

  10. 获取span中的值

    js-code:var baseinfoallfeesum=$("#allFeeSum").html(); $("#baseInfoAllFeeSum").va ...