QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#375199#6127. Kawa ExammurphyWA 2404ms57936kbC++144.4kb2024-04-02 23:20:492024-04-02 23:20:50

Judging History

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

  • [2024-04-02 23:20:50]
  • 评测
  • 测评结果:WA
  • 用时:2404ms
  • 内存:57936kb
  • [2024-04-02 23:20:49]
  • 提交

answer

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<queue>
#include<vector>
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> PII;
 
const int INF=0x3f3f3f3f, N=3e5+10;
const double eps=1e-6, PI=acos(-1);
 
int cases, n, m;
int dfn[N], low[N], dfs_cnt, stk[N], top, e_dcc, blk[N];
int col[N];

struct Node
{
    int a, cnt[N], num[N];

    void clear()
    {
        for (int i=1; i<=n; i++) cnt[col[i]]=0, num[i]=0;
        a=0;
    }

    void add(int x)
    {
        if (cnt[x]) num[cnt[x]]--;
        cnt[x]++; num[cnt[x]]++;
        a=max(a, cnt[x]);
    }

    void del(int x)
    {
        num[cnt[x]]--, cnt[x]--;
        if (cnt[x]) num[cnt[x]]++;
        a=num[a]>0 ? a: a-1;
    }
}D1, D2;

struct Edge
{
    int v, w, nxt;
}e[N];
int h[N], ecnt;

void add(int u, int v, int w)
{
    e[ecnt].nxt=h[u], e[ecnt].v=v, e[ecnt].w=w, h[u]=ecnt++;
}

void tarjan(int u,int from)
{
    dfn[u]=low[u]=++dfs_cnt;
    stk[++top]=u;
    
    for (int i=h[u];i!=-1;i=e[i].nxt)
    {
        int v=e[i].v;
        if (!dfn[v])
        {
            tarjan(v,i);
            low[u]=min(low[u],low[v]);
        }
        else if (i!=(from^1)) low[u]=min(low[u], dfn[v]);
    }
    
    if (low[u]==dfn[u])
    {
        int y;
        e_dcc++;
        do
        {
            y=stk[top--];
            blk[y]=e_dcc;
        } while (y!=u);
    }
}

vector<int> G[N], nums[N], E[N];
int siz[N], son[N], id[N], idx=0, L[N], R[N];

void dfs1(int u, int fa)
{
    idx++; siz[u]=(int)nums[u].size(), id[idx]=u;
    L[u]=idx;
    for (auto v:G[u])
    {
        if (v==fa) continue;
        dfs1(v, u);
        siz[u]+=siz[v];
        if (siz[son[u]] < siz[v]) son[u]=v; 
    }
    R[u]=idx;
}

int ans[N];
void dfs2(int u, int fa, int keep, int all, int edge)
{
    for (int i=0; i<(int)G[u].size(); i++)
    {
        int v=G[u][i], w=E[u][i];
        if (son[u] && v==son[u]) dfs2(son[u], u, 1, all, w);
        else if (v!=fa) dfs2(v, u, 0, all, w);
    }
    for (int i=0; i<(int)G[u].size(); i++)
    {
        int v=G[u][i], w=E[u][i];
        if (v==fa || v==son[u]) continue;
        for (int j=L[v]; j<=R[v]; j++) for (auto x:nums[id[j]]) D1.add(x), D2.del(x);
    }
    for (auto x:nums[u]) D1.add(x), D2.del(x);

    if (edge) ans[edge]=D1.a+D2.a-all;
    if (!keep)
    {
        for (int i=L[u]; i<=R[u]; i++)
            for (auto x:nums[id[i]]) D1.del(x), D2.add(x);
    }
}

void init()
{
    memset(h, -1, sizeof(h)); ecnt=0;
    memset(dfn, 0, sizeof(dfn)); memset(low, 0, sizeof(low)); dfs_cnt=0;
    top=0; memset(blk, 0, sizeof(blk)); e_dcc=0;
    idx=0; memset(son, 0, sizeof(son)); memset(L, 0, sizeof(L)); 
    memset(ans, 0, sizeof(ans));
}

void mian(int dt)
{
    init();
    cin>>n>>m;
    for (int i=1; i<=n; i++) cin>>col[i];
    if (dt==12) {
        cout<<n<<" "<<m<<" ";
        for (int i=14; i<=n; i++) 
        {
            cout<<col[i]<<" "; 
            if (rand()%2) cout<<endl;
        }
        cout<<endl;
    }
    
    for (int i=1; i<=m; i++)
    {
        int x, y; cin>>x>>y; add(x, y, i); add(y, x, i);
    }
    for (int i=1; i<=n; i++) if (!dfn[i]) tarjan(i, -1);
    for (int i=1; i<=e_dcc; i++) nums[i].clear(), G[i].clear(), E[i].clear();
    for (int i=1; i<=n; i++) nums[blk[i]].push_back(col[i]);

    for (int i=1; i<=n; i++)
    {
        for (int j=h[i]; j!=-1; j=e[j].nxt)
        {
            int v=e[j].v, w=e[j].w;
            if (blk[i] != blk[v])
            {
                G[blk[i]].push_back(blk[v]); E[blk[i]].push_back(w);
            }
        }
    }

    for (int i=1; i<=e_dcc; i++)
    {
        if (!L[i])
        {
            dfs1(i, -1);
            for (int j=L[i]; j<=R[i]; j++)
            {
                for (auto x:nums[id[j]]) 
                {
                    D2.add(x);
                }   
            }
            ans[0]+=D2.a;   
            dfs2(i, -1, 0, D2.a, 0);
            for (int j=L[i]; j<=R[i]; j++)
            {
                for (auto x:nums[id[j]]) 
                {
                    D2.del(x);
                }
            }
        }
    }

    for (int i=1; i<m; i++) cout<<ans[i]+ans[0]<<" ";
    cout<<ans[m]+ans[0]<<endl;
    D1.clear(), D2.clear();
}   

int main()
{
    cin>>cases;
    for (int i=1; i<=cases; i++) mian(i);
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 43012kb

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: 2404ms
memory: 57936kb

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
20 20 56150 
52079 35724 
22916 
35724 
35724 
52079 
11 10 11 10 12 11 10 10 10 10 10 10 10...

result:

wrong answer 12th lines differ - expected: '10 10 11 10 12 11 10 10 10 10 10 10 10 12 10 10 10 10 10 11', found: '20 20 56150 '