最小生成树 kuangbin专题最后一个题

题目链接:https://cn.vjudge.net/contest/66965#problem/N

注释:这道题需要用krustra,用prim的话可能会超时。并且在计算距离的时候要尽量减少步骤,具体注意事项在代码中说吧。

AC代码:

#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
# define inf 0x3f3f3f3f
# define maxn 5000
int father[maxn];
struct Point
{
    int x,y;
} q[maxn];
struct Edge
{
    int fr;
    int to;
    double cost;
} edge[maxn];
double cal(int t1,int t2)
{
    double s1=(q[t1].x-q[t2].x);
    double s2=(q[t1].y-q[t2].y);
    return (s1*s1+s2*s2);//不要直接计算sqrt,在累积和的时候计算
}
bool cmp(Edge t1,Edge t2)
{
    return t1.cost1000000.0)continue;
                    edge[++num].fr=i;
                    edge[num].to=j;
                    edge[num].cost=temp;
            }
        }
       // cout<

 

转载于:https://www.cnblogs.com/letlifestop/p/10262861.html

你可能感兴趣的:(最小生成树 kuangbin专题最后一个题)