[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. Awk basic and practice

    定义:Awk是一种程序语言,用来处理数据和产生报告.数据可来自标准输入,文件,管道输出. 格式:#awk '/pattern/ {action}' filename 术语:pattern, 样式是由正 ...

  2. 在线输入RGB更改背景色

    HTML: <!DOCTYPE html><html> <head> <meta http-equiv="Content-Type" co ...

  3. 【51NOD】1717 好数

    [算法]数学 [题意]a数组初始为0,t=1~n,每次01翻转t的倍数,最终为0的数字定义为好数,求好数个数 [题解]一个数字为好数的条件是翻转偶数次,也即一个数是好数当且仅当有偶数个因子时. 因子都 ...

  4. bzoj 1083 最小生成树

    裸的最小生成树. /************************************************************** Problem: User: BLADEVIL Lan ...

  5. pycharm设置 django模板语言

    ``` 参考:https://www.zhihu.com/question/65342278/answer/229993987 在setting-language&frameworks-pyt ...

  6. 转:selenium webdriver+python基本操作

    转自: http://blog.163.com/ly676830315@126/blog/static/1017337222013102310617946/ 导入模块: from selenium i ...

  7. HDU3746(KMP求循环节)

    Cyclic Nacklace Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  8. 中断处理函数中不用disable_irq而用disable_irq_nosync原因【转】

    转自:http://blog.csdn.net/beyondioi/article/details/9201695 今天在写触摸屏驱动时在中断处理函数中使用disable_irq关中断发现在进入中断处 ...

  9. ReadOnly与Enabled

    txtDlrCode.ReadOnly = true; 1.当设置为只读,文本框有点击事件,点击该文本框还是可以响应点击事件 2.设置为只读,C#后台无法取得文本框的值,txtDlrCode.Text ...

  10. JQ子页面对父页面的元素进行操作

    需要加上parent.document,才能找到父页面的元素 如: $("#tabs", parent.document).click();