H - Disjoint Set

https://vjudge.net/contest/279463#problem/H

#include
#include
#include
#include
#define ll long long
using namespace std;
struct str
{
    ll  t,n;
    ll w;
} e[1000010];
struct node
{
    ll  x;
    ll y;
    node(ll xx=0,ll yy=0)
    {
        x=xx;
        y=yy;
    }
    bool operator<(const node &s)const
    {
        if (y>s.y) return 1;
        else return 0;
    }
};
priority_queue q;
ll a,b,tt,n,m,i,s,j,k,t,h[100100],v[100100],l,d[100100],ans,kk,x,y,z;
char c[100];
void add(ll u,ll v,ll w)
{
    tt++;
    e[tt].t=v;
    e[tt].w=w;
    e[tt].n=h[u];
    h[u]=tt;
}
void dij()
{
    for (i=1; i<=n; i++)
        d[i]=10000000000;
    d[1]=0;
    q.push(node(1,0));
    while (!q.empty())
    {
        int k=q.top().x;
        q.pop();
        if (v[k]==1) continue;
        v[k]=1;
        for (int i=h[k];i!=0;i=e[i].n)
        {
            if (d[e[i].t]>d[k]+e[i].w)
            {
                d[e[i].t]=d[k]+e[i].w;
                q.push(node(e[i].t,d[e[i].t]));
            }
        }
    }
}
int main()
{
    scanf("%d",&n);
    for (i=2;i<=n;i++)
    for (j=1; j

 

你可能感兴趣的:(H - Disjoint Set)