当前位置:网站首页>[hdu] P7058 Ink on paper 求最小生成树的最大边
[hdu] P7058 Ink on paper 求最小生成树的最大边
2022-06-22 09:18:00 【Lupin123123】
题目链接
求最小生成树的最大边。
图是完全图,在稠密图中prim算法更优
#include<bits/stdc++.h>
#define FAST ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
typedef long long ll;
const int maxn = 1e5+5;
const ll INF = 1LL<<60;
using namespace std;
int n,m,tot;
ll dis[5005],mp[5001][5001];
int vis[5005];
struct P
{
ll x,y;
}p[5005];
ll cal(int i, int j){
return (p[i].x-p[j].x)*(p[i].x-p[j].x)+(p[i].y-p[j].y)*(p[i].y-p[j].y);
}
ll prime()
{
int now;
ll ans;
for (int i=1; i<=n; i++) dis[i]=INF, vis[i]=0;
dis[1]=0;
tot=0, now=1, ans=-1;
for (int t=1; t<=n; t++)
{
ll minn=INF;
for (int i=1; i<=n; i++){
if (!vis[i] && dis[i]<minn){
minn=dis[i];
now=i;
}
}
vis[now]=1;
ans=max(ans,dis[now]);
for (int j=1; j<=n; j++)
if (!vis[j] && mp[now][j]<dis[j]) dis[j]=mp[now][j];
}
return ans;
}
void solve()
{
cin>>n;
for (int i=1; i<=n; i++){
for (int j=1; j<=n; j++)
mp[i][j]=0;
}
for (int i=1; i<=n; i++)
cin>>p[i].x>>p[i].y;
for (int i=1; i<=n; i++){
for (int j=i+1; j<=n; j++)
mp[i][j]=mp[j][i]=cal(i,j);
}
ll res=prime();
cout<<res<<endl;
}
int main()
{
FAST;
// freopen("1.in","r",stdin);
int kase;
cin>>kase;
while(kase--)
{
solve();
}
return 0;
}
边栏推荐
- 进程状态汇总
- 断言assert()
- User insight into the video industry in January 2022: active users began to pick up under the influence of holidays
- Sound and shadow 2022 heavy release! Detailed explanation of the new functions of Huisheng Huiying 2022
- It is hoped that more and more women will engage in scientific and technological work
- 经典&&案例
- 機器學習|nltk_Data下載錯誤|nltk的stopwords語料下載錯誤解决方法
- Brush questions in C language | judge whether a certain year is only a leap year (15)
- Debian10 创建用户、用户组、切换用户
- Debian10 LVM逻辑卷
猜你喜欢

機器學習|nltk_Data下載錯誤|nltk的stopwords語料下載錯誤解决方法

机器学习|nltk_Data下载错误|nltk的stopwords语料下载错误解决方法

User insight into the video industry in January 2022: active users began to pick up under the influence of holidays

Performance optimization topics

Opencv daily function histogram correlation (3)

VMware installation Kali

值(址)传递,看清名字,别掉沟里

Mapping multiple exit servers on ENSP

Kali Trojan invades win7 system
![[node] please accept the crawler. We won't worry about the data any more](/img/f1/cb2ab621f9f714b650f0fbe3a26afa.png)
[node] please accept the crawler. We won't worry about the data any more
随机推荐
Assert()
Map三种遍历方式,秒懂,你懂
MySQL中常用的SQL语句
A readme of an old open source person - how to do open source well
Share 830 spider IP segments (by analyzing 1g logs)
[uni app] actual combat summary (including multi terminal packaging)
使用ELK保存Syslog、Netflow日志和审计网络接口流量
Project optimization + online (Master?)
Let you get started [uni app]
PHP online common color comparison table
Traifik ingress practice
mknod
集合中的类--->你关注过那些是线程安全的吗?
DOM programming
Process status summary
Opencv daily function histogram correlation (3)
Debian10 创建用户、用户组、切换用户
Apprentissage automatique | nltk Erreur de téléchargement des données | solution d'erreur de téléchargement du corpus stopwords pour nltk
File upload attack and protection
Originality: dozens of lines of pure PHP code decrypt goto encrypted PHP single file [for learning only]