牛客寒假6-I 导航系统
链接:https://ac.nowcoder.com/acm/contest/3007/I
来源:牛客网
题目描述
输入描述:
输出描述:
输出
复制 No
No
题解
跑一遍MST得出道路长度长,跑一遍Floyd处理出任意两点间距离并与导航给出的距离对比
CODE
#include <bits/stdc++.h>
#define dbg(x) cout << #x << "=" << x << endl
#define eps 1e-8
#define pi acos(-1.0) using namespace std;
typedef long long LL; template<class T>inline void read(T &res)
{
char c;T flag=;
while((c=getchar())<''||c>'')if(c=='-')flag=-;res=c-'';
while((c=getchar())>=''&&c<='')res=res*+c-'';res*=flag;
} namespace _buff {
const size_t BUFF = << ;
char ibuf[BUFF], *ib = ibuf, *ie = ibuf;
char getc() {
if (ib == ie) {
ib = ibuf;
ie = ibuf + fread(ibuf, , BUFF, stdin);
}
return ib == ie ? - : *ib++;
}
} int qread() {
using namespace _buff;
int ret = ;
bool pos = true;
char c = getc();
for (; (c < '' || c > '') && c != '-'; c = getc()) {
assert(~c);
}
if (c == '-') {
pos = false;
c = getc();
}
for (; c >= '' && c <= ''; c = getc()) {
ret = (ret << ) + (ret << ) + (c ^ );
}
return pos ? ret : -ret;
} const int maxn = ; struct node
{
int u,v,w;
}e[maxn*maxn]; int fa[maxn];
LL g[maxn][maxn];
LL dis[maxn][maxn]; int tot[maxn]; int fid(int x)
{
return fa[x]==x ? x : fa[x] = fid(fa[x]);
} bool cmp(node a,node b)
{
return a.w < b.w;
} int main()
{
int n;
int num=,x,sum=;
read(n);
for(int i = ; i <= n; ++i) {
for(int j = ; j <= n; ++j) {
read(x);
g[i][j] = x;
if(i != j)
{
e[++num].w=x;
e[num].u=i;
e[num].v=j;
}
}
}
sort(e+,e+num+,cmp);
for(int i = ; i <= n; ++i) {
for(int j = ; j <= n; ++j) {
if(i == j) dis[i][j] = ;
else dis[i][j] = 1e18;
}
}
for(int i = ; i <= n; ++i) {
fa[i] = i;
}
int u,v;
for(int i = ;i <= num; ++i) {
u = e[i].u;
v = e[i].v;
if(fid(u)!=fid(v))
{
dis[u][v] = dis[v][u] = e[i].w;
tot[++sum] = e[i].w;
fa[fa[u]] = fa[v];
}
}
for(int k = ; k <= n; ++k) {
for(int i = ; i <= n; ++i) {
for(int j = ; j <= n; ++j) {
dis[i][j] = min(dis[i][j], dis[i][k]+dis[k][j]);
}
}
}
for(int i = ; i <= n; ++i) {
for(int j = ; j <= n; ++j) {
if(dis[i][j] != g[i][j]) {
printf("No");
return ;
}
}
}
printf("Yes\n");
sort(tot+,tot+n);
for(int i = ; i < n; ++i) {
printf("%d\n",tot[i]);
}
}
牛客寒假6-I 导航系统的更多相关文章
- 2020牛客寒假算法基础集训营2 J题可以回顾回顾
2020牛客寒假算法基础集训营2 A.做游戏 这是个签到题. #include <cstdio> #include <cstdlib> #include <cstring ...
- 2020牛客寒假算法基础集训营1 J题可以回顾回顾
2020牛客寒假算法基础集训营1 这套题整体来说还是很简单的. A.honoka和格点三角形 这个题目不是很难,不过要考虑周全,面积是1,那么底边的长度可以是1也可以是2, 注意底边1和2会有重复的, ...
- 欧拉函数-gcd-快速幂(牛客寒假算法基础集训营1-D-小a与黄金街道)
题目描述: 链接:https://ac.nowcoder.com/acm/contest/317/D来源:牛客网小a和小b来到了一条布满了黄金的街道上.它们想要带几块黄金回去,然而这里的城管担心他们拿 ...
- Applese 的毒气炸弹 G 牛客寒假算法基础集训营4(图论+最小生成树)
链接:https://ac.nowcoder.com/acm/contest/330/G来源:牛客网 Applese 的毒气炸弹 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 262 ...
- 牛客寒假算法基础集训营3处女座和小姐姐(三) (数位dp)
链接:https://ac.nowcoder.com/acm/contest/329/G来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言52428 ...
- 牛客寒假算法基础集训营3B 处女座的比赛资格(用拓扑排序解决DAG中的最短路)
链接:https://ac.nowcoder.com/acm/contest/329/B 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言5242 ...
- 牛客寒假算法基础训练集中营4 E题 Applese 涂颜色
链接:https://ac.nowcoder.com/acm/contest/330/E 来源:牛客网 题目描述 精通程序设计的 Applese 叕写了一个游戏. 在这个游戏中,有一个 n 行 m 列 ...
- 牛客寒假算法基础集训营4 I题 Applese 的回文串
链接:https://ac.nowcoder.com/acm/contest/330/I 来源:牛客网 自从 Applese 学会了字符串之后,精通各种字符串算法,比如--判断一个字符串是不是回文串. ...
- 牛客寒假算法基础集训营4 F Applese 的大奖
链接:https://ac.nowcoder.com/acm/contest/330/H来源:牛客网 Applese 和它的小伙伴参加了一个促销的抽奖活动,活动的规则如下:有一个随机数生成器,能等概率 ...
随机推荐
- Update、Insert注入技巧
title: Update.Insert注入技巧 date: 2017-10-23 18:07:57 tags: ["注入"] 审计了不少代码,再看代码的时候最多出现的就是注入,很 ...
- Params:params 关键字可以指定在参数数目可变处采用参数的方法参数。
Params:params 关键字可以指定在参数数目可变处采用参数的方法参数. 注意点: 1.一个方法中只能使用一个params来声明不定长参数数组: 2.params参数数组只能放在已定义参数后面 ...
- XLNet:运行机制及和Bert的异同比较
这两天,XLNet貌似也引起了NLP圈的极大关注,从实验数据看,在某些场景下,确实XLNet相对Bert有很大幅度的提升.就像我们之前说的,感觉Bert打开两阶段模式的魔法盒开关后,在这条路上,会有越 ...
- Linux Firewalld用法及案例
Firewalld概述 动态防火墙管理工具 定义区域与接口安全等级 运行时和永久配置项分离 两层结构 核心层 处理配置和后端,如iptables.ip6tables.ebtables.ipset和模块 ...
- es5实现一个class
es5实现一个class https://juejin.im/post/5ac1c5bf518825558949f898#heading-9
- h5笔记(实战)
1.margin:auto 水平居中只对block有效,对inline和inline-block都无效 2.text-align:center 内容居中对block和inline-block有效,对i ...
- 前端项目引入Echarts中的dataTool的正确方式
使用echarts画箱线图时调用echarts.dataTool.prepareBoxplotData() 报错:"echarts.dataTool.prepareBoxplotData i ...
- transient关键字和serialVersionUID
此文章很大部分转载于Java的架构师技术栈微信公众号,博主均测试通过加上自己理解写出 最近阅读java集合的源码,发现transient关键字,就了解了一下他的用法,transient关键字一般在实现 ...
- Debian 10 安装无线网卡驱动 (rtl8822be)
apt install firmware-realtek
- codewars--js--Large Factorials--阶乘+大数阶乘
问题描述: In mathematics, the factorial of integer n is written as n!. It is equal to the product of n a ...