大佬们求条,hack全过官方炸了,玄关,马蜂良好
查看原帖
大佬们求条,hack全过官方炸了,玄关,马蜂良好
556955
123wbl楼主2024/11/28 17:19
#include<iostream>
#include<stack>
#include<cstring>
using namespace std;
struct edge
{
    int to,next,from;
}e[2000001],e1[2000001];
stack<int> st;
int n,m,head[400001],tot,dfn[400001],low[400001],a[400001];
int cnt,belong[400001],b[400001],sum,head1[400001];
int x[400001],y[400001],f[400001],ans;
void tarjan(int u)
{
    dfn[u]=low[u]=++cnt;
    st.push(u);
    b[u]=1;
    for(int i=head[u];i;i=e[i].next)
    {
        int v=e[i].to;
        if(!dfn[v])
        {
            tarjan(v);
            low[u]=min(low[u],low[v]);
        }
        else
            if(b[v])
                low[u]=min(low[u],low[v]);
    }
    if(dfn[u]==low[u])
    {
        sum++;
        while(st.top()!=u)
        {
            b[st.top()]=0;
            belong[st.top()]=sum;
            st.pop();
        }
        b[st.top()]=0;
        belong[st.top()]=sum;
        st.pop();
    }
}
inline void add(int u,int v)
{
    e[++tot].next=head[u];
    e[tot].to=v;
    e[tot].from=u;
    head[u]=tot;
}
inline void add1(int u,int v)
{
    e1[++tot].next=head1[u];
    e1[tot].to=v;
    e1[tot].from=u;
    head1[u]=tot;
}
void dfs(int u)
{
	ans=max(ans,y[u]-f[u]);
    for(int i=head1[u];i;i=e1[i].next)
    {
        int v=e1[i].to;
        f[v]=min(f[v],f[u]);
		dfs(v);
    }
}
int main()
{
    std::cin.tie(0)->sync_with_stdio(false);
    memset(x,0x3f,sizeof(x));
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=1;i<=m;i++)
    {
        int x,y,z;
        cin>>x>>y>>z;
        add(x,y);
        if(z==2) add(y,x);
    }
    for(int i=1;i<=n;i++)
        if(!dfn[i]) tarjan(i);
    int oo=tot;
    tot=0;
    for(int i=1;i<=oo;i++)
        if(belong[e[i].from]!=belong[e[i].to])
            add1(belong[e[i].from],belong[e[i].to]);
    for(int i=1;i<=n;i++)
    {
        if(x[belong[i]]>a[i])
            x[belong[i]]=a[i];
        if(y[belong[i]]<a[i])
            y[belong[i]]=a[i];
    }
    for(int i=1;i<=sum;i++)
        f[i]=x[i];
    dfs(belong[1]);
    cout<<ans;
}

调了一下感觉是建新图出了问题,但是调不出来

2024/11/28 17:19
加载中...