当前位置:网站首页>[hdu] p7058 ink on paper finding the maximum edge of the minimum spanning tree
[hdu] p7058 ink on paper finding the maximum edge of the minimum spanning tree
2022-06-23 01:23:00 【Lupin123123】
Topic link
Find the maximum edge of the minimum spanning tree .
Graph is complete graph , In dense graphs prim The algorithm is better
#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;
}
边栏推荐
- cadence SPB17.4 - allegro - 优化指定单条电气线折线连接角度 - 折线转圆弧
- 62. 不同路径
- OSPF comprehensive experiment
- 魔王冷饭||#099 魔王说西游;老板的本质;再答中年危机;专业选择
- Js--- SVG to png
- How to refine permissions to buttons?
- SAP ui5 application development tutorial 102 - detailed explanation of the print function of SAP ui5 applications
- BGP federal comprehensive experiment
- 一文读懂基于Redis的Amazon MemoryDB数据库
- 使用aggregation API扩展你的kubernetes API
猜你喜欢
随机推荐
Openvino CPU acceleration survey
Similar to attention NLP
SFOD:无源域适配升级优化,让检测模型更容易适应新数据
C#.NET万能数据库访问封装类(ACCESS、SQLServer、Oracle)
使用aggregation API扩展你的kubernetes API
一文读懂基于Redis的Amazon MemoryDB数据库
cadence SPB17.4 - allegro - 优化指定单条电气线折线连接角度 - 折线转圆弧
OSPF experiment in mGRE environment
Yyds dry inventory solution sword finger offer: print the binary tree into multiple lines
Wallys/DR7915-wifi6-MT7915-MT7975-2T2R-support-OpenWRT-802.11AX-supporting-MiniPCIe
Software construction course ADT and OOP understanding
魔王冷饭||#099 魔王说西游;老板的本质;再答中年危机;专业选择
SQL programming task03 job - more complex query
Found several packages [runtime, main] in ‘/usr/local/Cellar/go/1.18/libexec/src/runtime;
Ros2 summer school 2022 transfer-
Ansible learning summary (8) -- Summary of ansible control right raising related knowledge
Ansible learning summary (7) -- ansible state management related knowledge summary
LeetCode 206. Reverse linked list (iteration + recursion)
SYSTEMd summary
3DMAX modeling notes (I): introducing 3DMAX and creating the first model Hello World








