QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#526547#6127. Kawa Examwangyue2017WA 659ms36616kbC++143.2kb2024-08-21 17:22:192024-08-21 17:22:19

Judging History

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

  • [2024-08-21 17:22:19]
  • 评测
  • 测评结果:WA
  • 用时:659ms
  • 内存:36616kb
  • [2024-08-21 17:22:19]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N =1.1e5;
vector<pair<int,int> >E[N],e[N];
int col[N],bel[N];
int dfn[N],sk[N],low[N];
vector<int>a[N];
int ip=0,top=0,tot;
void dfs(int u,int ID){
    dfn[u]=low[u]=++ip;
    sk[++top]=u;
    for(auto [v,id]:E[u]){
        if(id==ID)continue;
        if(dfn[v]==0)dfs(v,id),low[u]=min(low[u],low[v]);
        else low[u]=min(low[u],dfn[v]);
    }
    if(dfn[u]==low[u]){
        ++tot;
        while(sk[top+1]!=u){
            bel[sk[top]]=tot;
            top--;
        }
    }
}



bool vis[N];
struct DATA
{
    int CNT[N],ton[N],MX;
    void ADD(int col){
        ton[CNT[col]]--;
        ++CNT[col];
        ton[CNT[col]]++;
        MX=max(MX,CNT[col]);
    }
    void DEL(int c){
        ton[CNT[c]]--;
        CNT[c]--;
        ton[CNT[c]]++;
        if(ton[MX]==0)MX--;
    }
    void add(int u,int fa){
        for(int x:a[u])ADD(x);
        for(auto [v,id]:e[u])if(v!=fa){
            add(v,u);
        }
    }
    void del(int u,int fa){
        for(int x:a[u])DEL(x);
        for(auto [v,id]:e[u])if(v!=fa){
            del(v,u);
        }
    }
}A,B;
int siz[N];
int ans[N];
int MX;
vector<int>now;

void init(int u,int fa){
    vis[u]=1;
    siz[u]=a[u].size();
    for(auto [v,id]:e[u])if(v!=fa)init(v,u),siz[u]+=siz[v];
}
void clear(){
    for(int x:now){
        B.DEL(x);
        A.ADD(x);
    }
    now.clear();
}
void push(int u,int fa){
    for(int x:a[u])now.push_back(x);
    for(auto [v,id]:e[u])if(v!=fa)push(v,u);
}
void DFS(int u,int fa){
    int son=0,ID;
    for(auto [v,id]:e[u])if(v!=fa)if(siz[v]>siz[son])son=v,ID=id;
    for(auto [v,id]:e[u])if(v!=son&&v!=fa){
        DFS(v,u);
        ans[id]=A.MX+B.MX-MX;
        clear();
    }
    if(son){DFS(son,u);
        ans[ID]=A.MX+B.MX-MX;
    }
    for(auto [v,id]:e[u])if(v!=son&&v!=fa)A.del(v,u),B.add(v,u),push(v,u);
    for(int x:a[u]){
        A.DEL(x);B.ADD(x);
        now.push_back(x);
    }
}
void solve(){
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;++i)cin>>col[i];
    for(int i=1;i<=m;++i){
        int u,v;
        cin>>u>>v;
        // if(u==v)continue;
        E[u].push_back({v,i});
        E[v].push_back({u,i});
    }
    for(int i=1;i<=n;++i)if(dfn[i]==0)dfs(i,0);
    for(int u=1;u<=n;++u){
        for(auto [v,id]:E[u]){
            if(bel[u]!=bel[v])e[bel[u]].push_back({bel[v],id});
        }
    }
    for(int i=1;i<=n;++i){
        a[bel[i]].push_back(col[i]);
    }
    int ori=0;
    for(int i=1;i<=n;++i){
        if(!vis[i]){
            A.add(i,0);
            init(i,0);
            MX=A.MX;
            ori+=A.MX;
            DFS(i,0);
            clear();
            A.del(i,0);
        }
    }
    for(int i=1;i<=m;++i){
        cout<<ans[i]+ori<<" \n"[i==m];
    }
    for(int i=1;i<=n;++i){
        a[i].clear();
        E[i].clear();
        e[i].clear();
        sk[i]=0;
        ip=0;
        top=0;
        tot=0;
        vis[i]=0;
        siz[i]=0;
        now.clear();
        MX=0;
        ans[i]=bel[i]=col[i]=dfn[i]=low[i]=0;
    }
}
signed main(){
    int T;
    cin>>T;
    while(T--){
        solve();
    }
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 14552kb

input:

3
7 5
1 2 1 2 1 2 1
1 2
1 3
2 4
5 6
5 7
3 3
1 2 3
1 2
1 3
2 3
2 3
12345 54321
1 2
1 2
1 1

output:

6 5 5 5 4
1 1 1
1 1 1

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 659ms
memory: 36616kb

input:

5557
2 7
79960 79960
2 2
1 1
1 1
2 2
1 1
2 1
1 2
9 8
21881 70740 70740 21881 22458 22458 639 21881 70740
3 3
1 6
5 8
7 5
5 7
2 3
5 1
7 6
6 7
13064 20716 6746 13064 6746 69225
5 5
4 1
4 1
1 6
4 5
3 2
3 2
8 4
45146 14400 45146 45146 14400 72969 14400 45146
8 6
1 3
4 6
8 3
18 13
48132 37949 92338 92338...

output:

2 2 2 2 2 2 2
6 6 7 6 6 6 6 6
3 3 3 4 4 3 3
7 7 7 7
9 9 9 8 9 8 9 8 9 9 10 9 9
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
7 8
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
9 10 9
16 16 16 16 16 17 16 16
10 10 11 10 12 11 10 10 10 10 10 10 10 12 10 10 10 10 10 11
10 9 9 9 9 9 9 9 9 9 9 9 9 9 10 ...

result:

wrong answer 19th lines differ - expected: '2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2', found: '2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2'