Perishable Roads

智商题, 不会啊。。

贴个官方题解

https://codeforces.com/blog/entry/51883

#include<bits/stdc++.h>
#define LL long long
#define LD long double
#define ull unsigned long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ALL(x) (x).begin(), (x).end()
#define fio ios::sync_with_stdio(false); cin.tie(0);using namespace std;const int N = 2000 + 7;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-8;
const double PI = acos(-1);template<class T, class S> inline void add(T &a, S b) {a += b; if(a >= mod) a -= mod;}
template<class T, class S> inline void sub(T &a, S b) {a -= b; if(a < 0) a += mod;}
template<class T, class S> inline bool chkmax(T &a, S b) {return a < b ? a = b, true : false;}
template<class T, class S> inline bool chkmin(T &a, S b) {return a > b ? a = b, true : false;}int n, mine = inf, G[N][N], d[N];
bool vis[N];int main() {scanf("%d", &n);for(int i = 1; i <= n; i++) {for(int j = i + 1; j <= n; j++) {scanf("%d", &G[i][j]);G[j][i] = G[i][j];chkmin(mine, G[i][j]);}}for(int i = 1; i <= n; i++) {for(int j = i + 1; j <= n; j++) {G[i][j] -= mine;G[j][i] -= mine;}}for(int i = 1; i <= n; i++) {d[i] = inf;for(int j = 1; j <= n; j++) {if(i != j) {chkmin(d[i], G[i][j] << 1);}}}d[0] = inf;for(int i = 1; i <= n; i++) {int p = 0;for(int j = 1; j <= n; j++) {if(!vis[j] && d[j] < d[p]) {p = j;}}for(int j = 1; j <= n; j++) {chkmin(d[j], d[p] + G[p][j]);}vis[p] = true;}for(int i = 1; i <= n; i++) printf("%lld\n", 1LL * (n - 1) * mine + d[i]);return 0;
}/*
*/

转载于:https://www.cnblogs.com/CJLHY/p/11098059.html

Codeforces 773D Perishable Roads 最短路 (看题解)相关推荐

  1. Codeforces 1155F Delivery Oligopoly dp(看题解)

    看别人写的才学会的... 我们考虑刚开始的一个点, 然后我们枚举接上去的一条一条链, dp[mask]表示当前已经加进去点的状态是mask所需的最少边数. 反正就是很麻烦的一道题, 让我自己写我是写不 ...

  2. Codeforces 494D Birthday 树形dp (看题解)

    Birthday 没想到平方和能在树上dp出来的... 知道了如何转移, 那么就很好写了... #include<bits/stdc++.h> #define LL long long # ...

  3. Codeforces 213E Two Permutations 线段树 (看题解)

    Two Permutations 关键是没想到按大小顺序把第二个排列一个一个加入线段树, 然后线段树维护整体的hash值, 得到的hs值减去一个sub 之后与, 第一个排列的hash值比较. #inc ...

  4. Codeforces 596D Wilbur and Trees dp (看题解)

    一直在考虑, 每一段的贡献, 没想到这个东西能直接dp..因为所有的h都是一样的. #include<bits/stdc++.h> #define LL long long #define ...

  5. codeforces773 D. Perishable Roads(思维+最短路)

    D. Perishable Roads 题意简述: 一个 nnn 个点的完全图 以 iii 为根节点时 询问 能构造的树的 ∑d(x)\sum d(x)∑d(x) 最小是多少. d(x)d(x)d(x ...

  6. Educational Codeforces Round 36 (Rated for Div. 2) 题解

    Educational Codeforces Round 36 (Rated for Div. 2) 题目的质量很不错(不看题解做不出来,笑 Codeforces 920C 题意 给定一个\(1\)到 ...

  7. CodeForces - 1196F K-th Path(最短路+思维)好题

    题目链接:点击查看 题目大意:给出一个 n 个点,m 条边的无向图,需要求出图中第 k 短的路径 题目分析:k 是 400,本来以为是需要思考 k * n 或 k * m 的算法,搞了半天最后原来是 ...

  8. Codeforces 1089D Eels (看题解)

    Eels 感觉想不出来这种东西.. 题解讲的很清楚啦. 我好lj啊. https://codeforces.com/blog/entry/64331 #include<bits/stdc++.h ...

  9. Codeforces 920D Tanks (看题解)

    Tanks 最关键的一点就是怎么判方案是否存在.. 只要存在若干个坦克之和的sum % k == v % k 就有解, 否则无解. 我怎么想不到呢... #include<bits/stdc++ ...

最新文章

  1. python中怎么比较两个列表-Python3列表(list)比较操作教程
  2. 28、FileThumbnails
  3. Windows 10使用PowerShell创建系统还原点的技巧
  4. 二叉树的最大深度—leetcode104
  5. mysql begin end 用法_超实用的Mysql动态更新数据库脚本的示例讲解(推荐)
  6. vfp报表纸张设置_VFP 9.0中实现多种自定义纸张格式的报表打印
  7. linux环境下qt实验报告,青岛科技大学实验报告(实验一).doc
  8. 计算机网络滑动窗口机制编程,计算机网络之滑动窗口机制
  9. Java对Internet为什么这么重要?
  10. Membership Leakage in Label-Only Exposures论文解读
  11. 计算机科学与技术实践教学,计算机科学与技术实践教学方法_精编版.doc
  12. IT不是技术,IT是一个世界
  13. xp系统wep服务器,iis 6.0 完整安装包 适用xp
  14. 智课雅思词汇---十九、前缀se是什么意思
  15. PlatformIO for CLion 创建工程时出现 gathering information问题解决方法
  16. 三星手机PIN码忘记锁机解决方法
  17. 微信小程序 之wx.previewImage图片预览(单张图片预览)
  18. 清除计算机垃圾cmd命令,dos命令清理垃圾,教你dos命令清理垃圾的方法
  19. HTML个人简历代码模板(静态页面)
  20. html纵向的跑马灯效果,单行文字垂直/水平跑马灯效果

热门文章

  1. java中io.nio.aio_Java中网络IO的实现方式-BIO、NIO、AIO
  2. rds基于什么开发_IaaS、PaaS、SaaS、DaaS都是什么?现在怎么样了?终于有人讲明白了...
  3. 网络验证php接口逆向,一个专利查错的逆向(网络验证)
  4. php oracle 配置,关于php:为Windows 64位配置Oracle OCI8
  5. MySQL的主动优化和被动优化_MySQL“被动”性能优化汇总!
  6. postgresq dur_DUR的完整形式是什么?
  7. gettype_PHP gettype()函数与示例
  8. PUSHAD和POPAD,以及PUSHA和POPA
  9. call和ret(f)指令
  10. 旧计算机 云桌面,该不该利用旧PC机改造成云桌面虚拟化模式呢?