其他分享
首页 > 其他分享> > 【JZOJ6357】小ω的图(graph)

【JZOJ6357】小ω的图(graph)

作者:互联网

description


analysis


code

#pragma GCC optimize("O3")
#pragma G++ optimize("O3")
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define MAXN 100005
#define MAXM 500005
#define ll long long
#define reg register ll
#define fo(i,a,b) for (reg i=a;i<=b;++i)
#define fd(i,a,b) for (reg i=a;i>=b;--i)

using namespace std;

ll x[MAXM],y[MAXM],z[MAXM];
ll fa[MAXN],pow[70],f[70];
ll n,m,ans;

inline ll read()
{
    ll x=0,f=1;char ch=getchar();
    while (ch<'0' || '9'<ch){if (ch=='-')f=-1;ch=getchar();}
    while ('0'<=ch && ch<='9')x=x*10+ch-'0',ch=getchar();
    return x*f;
}
inline ll getfa(ll x){return !fa[x]?x:fa[x]=getfa(fa[x]);}
inline void link(ll x,ll y){if (getfa(x)!=getfa(y))fa[getfa(x)]=getfa(y);}
int main()
{
    //freopen("T1.in","r",stdin);
    freopen("graph.in","r",stdin);
    freopen("graph.out","w",stdout);
    n=read(),m=read(),pow[0]=1;
    fo(i,1,62)pow[i]=pow[i-1]*2;
    fo(i,1,m)x[i]=read(),y[i]=read(),z[i]=read();
    fd(j,62,0)
    {
        ans+=pow[j],memset(fa,0,sizeof(fa));
        fo(i,1,m)if ((ans&z[i])==ans)link(x[i],y[i]);
        if (getfa(1)!=getfa(n))ans-=pow[j];
    }
    printf("%lld\n",ans);
    return 0;
}

标签:JZOJ6357,ch,graph,ll,MAXM,include,O3,define
来源: https://www.cnblogs.com/horizonwd/p/11535835.html