QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#93153#6127. Kawa ExamlamWA 1ms15696kbC++144.7kb2023-03-31 12:21:142023-03-31 12:21:14

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-31 12:21:14]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:15696kb
  • [2023-03-31 12:21:14]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
#define ff first
#define ss second
const int maxn = 1e5 + 10;
int n,m,k;
int res;
int a[maxn],ans[maxn],par[maxn],heavy[maxn],s[maxn];
int in[maxn],out[maxn],inv[maxn],id[maxn];
bool vis[maxn];
ii e[maxn];
vector <ii> adj[maxn],adj2[maxn];
vector <int> b[maxn];
int l[maxn],t[maxn],cnt;
stack <int> st;
struct ds
{
    int val[maxn],sl[maxn];
    int ans = 0;
    int _t;
    void reset(int type)
    {
        _t=type;
        fill_n(val,n+1,0);
        fill_n(sl,n+1,0);
        ans=0;
    }
    void add(int x)
    {
        sl[val[x]]--;
        val[x]++;
        sl[val[x]]++;
        ans=max(ans,val[x]);
    }
    void del(int x)
    {
        sl[val[x]]--;
        val[x]--;
        sl[val[x]]++;
        ans = (sl[ans]>0)?ans:(ans-1);
    }
};
ds s1,s2;
void dfs(int x, int p)
{
    st.push(x);
    l[x]=t[x]=++cnt;
    for (ii i:adj[x])
        if (i.ss!=p)
    {
        if (t[i.ff]==0)
        {
            dfs(i.ff,i.ss);
            l[x]=min(l[x],l[i.ff]);
        }
        else l[x]=min(l[x],t[i.ff]);
    }
    if (l[x]==t[x])
    {
        int temp; k++;
        do
        {
            temp=st.top(); st.pop();
            id[temp] = k;
            b[k].push_back(a[temp]);
        }
        while (temp!=x);
    }
}
void dfs2(int x, int p)
{
    vis[x] = 1;
    s[x] = b[x].size();
    in[x] = ++cnt;
    inv[cnt] = x;
    int temp = -1;
    for (ii i:adj2[x])
        if (i.ff!=p)
    {
        par[i.ff] = i.ss;
        dfs2(i.ff,x);
        s[x] += s[i.ff];
        if (temp==-1||s[i.ff]>s[temp]) temp = i.ff;
    }
    for (int i:b[x])
    {
        s2.add(i);
    }
    heavy[x] = temp;
    out[x] = cnt;
}
void dfs3(bool keep, int x, int p)
{
    for (ii i:adj2[x])
        if (i.ff!=p&&i.ff!=heavy[x]) dfs3(0,i.ff,x);
    if (heavy[x]!=-1) dfs3(1,heavy[x],x);
    for (ii i:adj2[x])
        if (i.ff!=p&&i.ff!=heavy[x])
            for (int j=in[i.ff]; j<=out[i.ff]; j++)
                for (int z:b[inv[j]])
    {
        s1.add(z);
        s2.del(z);
    }
    for (int i:b[x])
    {
        s1.add(i);
        s2.del(i);
    }
    if (par[x]!=-1)
    {
        ans[par[x]]+=s1.ans + s2.ans;
    }
    if (keep) return;
    for (int i=in[x]; i<=out[x]; i++)
        for (int j:b[inv[i]])
    {
        s1.del(j);
        s2.add(j);
    }
}
void xuly()
{

    cin>>n>>m;
    for (int i=1; i<=n; i++) b[i].clear();
    fill_n(vis,n+1,0);
    fill_n(t,n+1,0);
    fill_n(l,n+1,0);
    fill_n(par,n+1,-1);
    fill_n(ans,m+1,0);
    res=0;
    for (int i=1; i<=n; i++)
    {
        adj[i].clear();
        adj2[i].clear();
    }
    k=0; cnt=0;
    vector <int> aa;
    for (int i=1; i<=n; i++)
    {
        cin>>a[i];
        aa.push_back(a[i]);
    }
    sort(aa.begin(),aa.end());
    aa.resize(unique(aa.begin(),aa.end())-aa.begin());
    for (int i=1; i<=n; i++)
    {
        a[i]=lower_bound(aa.begin(),aa.end(),a[i])-aa.begin()+1;
    }
    for (int i=1; i<=m; i++)
    {
        int u,v; cin>>u>>v;
        adj[u].push_back({v,i});
        adj[v].push_back({u,i});
        e[i]={u,v};
    }
    for (int i=1; i<=n; i++) if (!t[i]) dfs(i,-1);
    for (int i=1; i<=m; i++)
    {
        int u,v; u=e[i].ff; v=e[i].ss;
        if (id[u]==id[v]) continue;
        u=id[u]; v=id[v];
        adj2[u].push_back({v,i});
        adj2[v].push_back({u,i});
    }
    res=0;
    cnt=0;
    s1.reset(1); s2.reset(2);
    n=k;
    for (int i=1; i<=n; i++) if (!vis[i])
    {
        par[i] = -1;
        dfs2(i,i);
        int val = s2.ans;
        dfs3(0,i,i);
        for (int j=in[i]; j<=out[i]; j++)
            for (int z:b[inv[j]]) s2.del(z);
        for (int j=in[i]+1; j<=out[i]; j++)
            ans[par[inv[j]]] -= val;
        res+=val;
    }
    for (int i=1; i<=m; i++)
    {
        ans[i]+=res;
        cout<<ans[i]<<' ';
    }cout<<'\n';
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int tt; cin>>tt;
    while (tt--) xuly();
}
/**
18
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
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
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
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
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
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
**/

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 15696kb

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:

wrong answer 1st lines differ - expected: '6 5 5 5 4', found: '6 5 5 5 4 '