求助,本机AC,提交RE
查看原帖
求助,本机AC,提交RE
85682
绝顶我为峰kkksd06楼主2020/7/24 20:57

下载数据本地跑得出来,而且是对的,但是交上去就全RE。。。

求帮助

#include<iostream>
#include<cstdio>
#include<map>
#include<algorithm>
using namespace std;
int n,m,p,fa[110001],ch[110001][2],val[110001],maxn[110001],top,stack[110001];
bool tag[11001],vis[10001];
struct question
{
    int opt,x,y,num,ans;
}q[100001];
struct edge
{
    int x,y,weight;
    bool operator <(const edge &other) const
    {
        return weight<other.weight;
    }
}e[100001];
map<pair<int,int>,int> id;
inline void push_up(int x)
{
    maxn[x]=val[x];
    if(e[maxn[ch[x][0]]].weight>e[maxn[x]].weight)
        maxn[x]=maxn[ch[x][0]];
    if(e[maxn[ch[x][1]]].weight>e[maxn[x]].weight)
        maxn[x]=maxn[ch[x][1]];
}
inline bool nroot(int x)
{
    return x==ch[fa[x]][0]||x==ch[fa[x]][1];
}
inline void update(int x)
{
    ch[x][0]^=ch[x][1]^=ch[x][0]^=ch[x][1];
    tag[x]^=1;
}
inline void push_down(int x)
{
    if(tag[x])
    {
        if(ch[x][0])
            update(ch[x][0]);
        if(ch[x][1])
            update(ch[x][1]);
        tag[x]=0;
    }
}
inline void rotate(int x)
{
    int y=fa[x],z=fa[y],k=x==ch[y][1];
    if(nroot(y))
        ch[z][y==ch[z][1]]=x;
    ch[y][k]=ch[x][k^1];
    if(ch[x][k^1])
        fa[ch[x][k^1]]=y;
    ch[x][k^1]=y;
    fa[y]=x;
    fa[x]=z;
    push_up(y);
}
inline void splay(int x)
{
    int y=x;
    stack[top=1]=y;
    while(nroot(y))
        stack[++top]=y=fa[y];
    while(top)
        push_down(stack[top--]);
    while(nroot(x))
    {
        int y=fa[x],z=fa[y];
        if(nroot(y))
            rotate((x==ch[y][0])^(y==ch[z][0])? x:y);
        rotate(x);
    }
    push_up(x);
}
inline void access(int x)
{
    for(register int y=0;x;x=fa[y=x])
    {
        splay(x);
        ch[x][1]=y;
        push_up(x);
    }
}
inline void makeroot(int x)
{
    access(x);
    splay(x);
    update(x);
}
inline int findroot(int x)
{
    access(x);
    splay(x);
    while(ch[x][0])
    {
        push_down(x);
        x=ch[x][0];
    }
    splay(x);
    return x;
}
inline void split(int x,int y)
{
    makeroot(x);
    access(y);
    splay(y);
}
inline void link(int x,int y)
{
    makeroot(x);
    if(findroot(x)!=y)
        fa[x]=y;
}
inline void cut(int x,int y)
{
    makeroot(x);
    if(findroot(y)!=x||fa[y]!=x||ch[x][0])
        return;
    fa[y]=ch[x][1]=0;
    push_up(x);
}
int main()
{
    maxn[0]=-1<<30;
    scanf("%d%d%d",&n,&m,&p);
    for(register int i=1;i<=m;++i)
    {
        scanf("%d%d%d",&e[i].x,&e[i].y,&e[i].weight);
        if(e[i].x>e[i].y)
            e[i].x^=e[i].y^=e[i].x^=e[i].y;
    }
    sort(e+1,e+m+1);
    for(register int i=1;i<=m;++i)
    {
        id[make_pair(e[i].x,e[i].y)]=i;
        val[i+n]=maxn[i+n]=i;
    }
    for(register int i=1;i<=p;++i)
    {
        scanf("%d%d%d",&q[i].opt,&q[i].x,&q[i].y);
        if(q[i].x>q[i].y)
            q[i].x^=q[i].y^=q[i].x^=q[i].y;
        if(q[i].opt==2)
        {
            q[i].num=id[make_pair(q[i].x,q[i].y)];
            vis[q[i].num]=1;
        }
    }
    for(register int i=1;i<=m;++i)
        if(!vis[i]&&findroot(e[i].x)!=findroot(e[i].y))
        {
            link(e[i].x,i+n);
            link(e[i].y,i+n);
        }
    for(register int i=p;i>=1;--i)
    {
        if(q[i].opt==1)
        {
            split(q[i].x,q[i].y);
            q[i].ans=e[maxn[q[i].y]].weight;
        }
        if(q[i].opt==2)
        {
            split(q[i].x,q[i].y);
            if(e[q[i].num].weight<e[maxn[q[i].y]].weight)
            {
                cut(e[maxn[q[i].y]].x,maxn[q[i].y]+n);
                cut(e[maxn[q[i].y]].y,maxn[q[i].y]+n);
                link(q[i].x,q[i].num+n);
                link(q[i].y,q[i].num+n);
            }
        }
    }
    for(register int i=1;i<=p;++i)
        if(q[i].opt==1)
            printf("%d\n",q[i].ans);
    return 0;
}
2020/7/24 20:57
加载中...