QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#306925#8055. Balanceinstallb#Compile Error//C++146.0kb2024-01-17 16:43:472024-01-17 16:43:48

Judging History

你现在查看的是最新测评结果

  • [2024-01-17 16:43:48]
  • 评测
  • [2024-01-17 16:43:47]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define M 200005
struct EDGE{
    int to,nx;
}Edge[M<<1];
int tt,h[M],K,B[M];
void link(int a,int b){
    Edge[++tt].to=b;
    Edge[tt].nx=h[a];
    h[a]=tt;
}
int n,m;
using ll = long long;
using pii = pair<int,int>;
int dfn[M],dfc,low[M],col[M],cco,bri[M],A[M],siz[M];
void tarjan(int u,int fe){
    dfn[u] = low[u] = ++dfc;
    for(int i=h[u];i;i=Edge[i].nx){
        int v = Edge[i].to;
        if(!dfn[v]){
            tarjan(v,i);
            low[u]=min(low[u],low[v]);
            if(low[v]>dfn[u])bri[i]=bri[i^1]=1;
        }else if(i!=(fe^1))low[u]=min(low[u],dfn[v]);
    }
}
void dfs_dcc(int u,int id){
    col[u] = id;
    for(int i=h[u];i;i=Edge[i].nx){
        int v = Edge[i].to;
        if(bri[i] || col[v])continue;
        dfs_dcc(v,id);
    }
}
vector<int>edge[M];
void Work(){
    for(int i=1;i<=n;i++){
        edge[i].clear();
        dfn[i]=low[i]=col[i]=bri[i]=0;
    }
    dfc = cco = 0;
    for(int i=1;i<=n;i++)if(!dfn[i])tarjan(i,0);
    cco = 0;
    for(int i=1;i<=n;i++){
        if(col[i])continue;
        cco++;
        dfs_dcc(i,cco);
    }
    for(int i=1;i<=n;i++)siz[col[i]]++;
    set<pii> S;
    for(int now=1;now<=n;now++)
        for(int i=h[now];i;i=Edge[i].nx){
            int to = Edge[i].to;
            if(col[to]!=col[now] && !S.count(pii(col[to],col[now]))){
                edge[col[to]].push_back(col[now]);
                edge[col[now]].push_back(col[to]);
                S.insert(pii(col[to],col[now]));
                S.insert(pii(col[now],col[to]));
            }
        }
}
int sz_val[M],Fr[M],Be[M],sz_T[M],sum_val[M];
int hv_ans_b[M];
int Ans_a,Ans_b,Ans_c,Ans_d;
int Lx[M],Rx[M],Index,ln[M];
int f[M][2],f_pre[M][2];
int par[M];
vector<int>belong[M];
void dfs(int F,int now){
    par[now]=F;
    ln[Lx[now]=++Index]=now;
    f[now][0]=0,f[now][1]=K+1;
    sz_T[now] = siz[M];
    for(int &to:edge[now])if(to!=F){
        dfs(now,to);
        sz_T[now] += sz_T[to];
        if(f[to][0]>f[now][0]){
            f[now][0]=f[to][0];
            f_pre[now][0] = f_pre[to][0];
        }
        if(f[to][1]>f[now][1]){
            f[now][1]=f[to][1];
            f_pre[now][1] = f_pre[to][1];
        }
        if(!hv_ans_b[to])hv_ans_b[now] = hv_ans_b[to];
    }
    if(f[now][0] == Fr[sz_T[now]]-1 && sz_T[now] ==  sum_val[Fr[sz_T[now]]]){
        f[now][0]++;
        f_pre[now][0]=now;
        if(f[now][0] == K-1)Ans_c = now;
    }
    if(f[now][1] == Be[sz_T[now]]+1 && sz_T[now] ==  n-sum_val[Be[sz_T[now]]-1]){
        f[now][1]--;
        f_pre[now][1]=now;
        if(f[now][1] == K)hv_ans_b[now] = now;
        if(f[now][1] == 2)Ans_d = now;
    }
    Rx[now]=Index;
}
void redfs(int F,int now,int hv_ans_bb){
    int fi=0,se=0;
    for(int &to:edge[now])if(to!=F){
        if(hv_ans_b[to]){
            if(!fi)fi = hv_ans_b[to];
            else se = hv_ans_b[to];
        }
    }
    for(int &to:edge[now])if(to!=F){
        int tag = hv_ans_bb;
        if(!tag && hv_ans_b[to] && hv_ans_b[to]!=fi)tag = fi;
        else if(!tag && hv_ans_b[to] && hv_ans_b[to]!=se)tag = se;
        redfs(now,to,tag);
    }
    if(hv_ans_bb && f[now][0] == K-2 && sz_T[now] ==  sum_val[Fr[sz_T[now]]]){
        Ans_a=now, Ans_b=hv_ans_bb;
    }
}
int Ans[M];
void get_ans(int now,int v,int flg,int d){//-1 for 1 and 1 for 0
    if(v==K && d==1 || v==1 && d==-1){
        for(int i=Lx[now];i<=Rx[now];i++)
            for(int &x:belong[ln[i]])Ans[x]=v;
        return;
    }
    int nex = -1;
    for(int &to:edge[now])if(to!=par[now]){
        if(f[to][flg] == f[now][flg]-1)
            nex = f_pre[to][flg];
    }
    assert(nex != -1);
    for(int i=Lx[now];i<Lx[nex];i++)
        for(int &x:belong[ln[i]])Ans[x]=v;
    for(int i=Rx[nex]+1;i<=Rx[now];i++)
        for(int &x:belong[ln[i]])Ans[x]=v;
    get_ans(nex,v+d,flg,d);
}
void Reset(){
    memset(h+1,0,n<<2);
    tt=1;
    for(int i=1;i<=n;i++){
        belong[i].clear();
        edge[i].clear();
        siz[i]=sz_val[i]=hv_ans_b[i]=0;
        f[i][0]=f[i][1]=f_pre[i][0]=f_pre[i][1]=0;
    }
    Index=0;
}
int main(){
    int Cas;cin>>Cas;
    while(Cas--){
        scanf("%d%d",&n,&m);
        Reset();
        for(int i=1,a,b;i<=m;i++){
            scanf("%d%d",&a,&b);
            link(a,b),link(b,a);
        }
        Work();
        static int mark[M],pos[M];
        for(int i=1;i<=n;i++)mark[i]=0;
        for(int i=1;i<=n;i++)scanf("%d",&A[i]),mark[A[i]]=1;
        K = 0;
        for(int i=1;i<=n;i++)
            if(mark[i])B[pos[i]=++K]=i;
        if(K==1){
            puts("Yes");
            for(int i=1;i<=n;i++)printf("%d ",A[1]);
            puts("");
            continue;
        }
        Ans_a=Ans_b=0;
        for(int i=1;i<=n;i++){
            A[i]=pos[A[i]];
            sz_val[A[i]]++;
        }
        for(int i=1;i<=K;i++)sum_val[i] = sz_val[i] + sum_val[i-1];
        for(int i=1,s=0;i<=K;i++){
            for(int j=s+1;j<=s+sz_val[i];j++)Fr[j] = i;
            s+=sz_val[i];
        }
        for(int i=K,s=0;i>=1;i--){
            for(int j=s+1;j<=s+sz_val[i];j++)Be[j] = i;
            s+=sz_val[i];
        }
        Ans_a=Ans_b=Ans_c=Ans_d=0;
        dfs(0,1);
        redfs(0,1,0);
        if(K>2 && Ans_a){
            puts("Yes");
            get_ans(Ans_a,K-2,0,-1);
            get_ans(Ans_b,K,1,1);
            for(int i=1;i<=n;i++)
                if(Ans[i])printf("%d ",B[Ans[i]]);
                else printf("%d ",B[K-1]);
            puts("");
        }else if(Ans_c){
            puts("Yes");
            get_ans(Ans_c,K-1,0,-1);
            for(int i=1;i<=n;i++)
                if(Ans[i])printf("%d ",B[Ans[i]]);
                else printf("%d ",B[K]);
            puts("");
        }else if(Ans_d){
            puts("Yes");
            get_ans(Ans_d,2,1,1);
            for(int i=1;i<=n;i++)
                if(Ans[i])printf("%d ",B[Ans[i]]);
                else printf("%d ",B[1]);
            puts("");
        }else puts("No");
    }
    return 0;
}asdasd

詳細信息

answer.code:213:2: error: ‘asdasd’ does not name a type
  213 | }asdasd
      |  ^~~~~~
answer.code: In function ‘int main()’:
answer.code:152:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  152 |         scanf("%d%d",&n,&m);
      |         ~~~~~^~~~~~~~~~~~~~
answer.code:155:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  155 |             scanf("%d%d",&a,&b);
      |             ~~~~~^~~~~~~~~~~~~~
answer.code:161:35: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  161 |         for(int i=1;i<=n;i++)scanf("%d",&A[i]),mark[A[i]]=1;
      |                              ~~~~~^~~~~~~~~~~~