QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#733707#8055. Balanceucup-team4479WA 3ms13784kbC++234.2kb2024-11-10 20:35:012024-11-10 20:35:01

Judging History

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

  • [2024-11-10 20:35:01]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:13784kb
  • [2024-11-10 20:35:01]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
constexpr int N=100005;
struct Trajan_EBC
{
    int n,m;
    Trajan_EBC(int _n=0):n(_n),m(0){}
    void init(int _n)
    {
        for(int i=1;i<=n;i++)
            G[i].clear();
        n=_n,m=0;
        return;
    }
    vector<pair<int,int>>G[N];
    void add_edge(int u,int v)
    {
        m++;
        G[u].emplace_back(v,m);
        G[v].emplace_back(u,m);
        return;
    }
    int dfn[N],low[N],idx;
    bool ins[N];
    stack<int>s;
    int bel[N],tot;
    vector<int>block[N];
    void dfs(int u,int prev)
    {
        dfn[u]=low[u]=++idx;
        ins[u]=true;
        s.push(u);
        for(auto [v,id]:G[u])
        {
            if(id==prev) continue;
            if(!dfn[v])
            {
                dfs(v,id);
                low[u]=min(low[u],low[v]);
            }
            else if(ins[v]) low[u]=min(low[u],dfn[v]);
        }
        if(dfn[u]==low[u])
        {
            tot++;
            block[tot].clear();
            while(!s.empty()&&s.top()!=u)
            {
                int v=s.top();
                s.pop();
                ins[v]=false;
                bel[v]=tot;
                block[tot].push_back(v);
            }
            s.pop();
            ins[u]=false;
            bel[u]=tot;
            block[tot].push_back(u);
        }
        return;
    }
    void tarjan()
    {
        fill(dfn+1,dfn+n+1,0);
        fill(low+1,low+n+1,0);
        idx=0;
        fill(bel+1,bel+n+1,0);
        tot=0;
        fill(ins+1,ins+n+1,false);
        for(int i=1;i<=n;i++)
            if(!dfn[i]) dfs(i,0);
        return;
    }
}ebc;
int n,m;
int a[N];
vector<int>G[N];
pair<int,int> f[N],g[N];
tuple<int,int,int> h[N];
int siz[N];
int fa[N];
void dfs(int u,int father)
{
    f[u]=g[u]={0,u};
    siz[u]=ebc.block[u].size();
    h[u]={0,u,u};
    fa[u]=father;
    for(int v:G[u])
    {
        if(v==father) continue;
        dfs(v,u);
        siz[u]+=siz[v];
        h[u]=max(h[u],h[v]);
        h[u]=max(h[u],make_tuple(f[u].first+g[v].first+(a[n-siz[v]]!=a[n-siz[v]+1]),f[u].second,g[v].second));
        h[u]=max(h[u],make_tuple(f[u].first+g[v].first+(a[siz[v]]!=a[siz[v]+1]),f[v].second,g[u].second));
        f[u]=max(f[u],make_pair(f[v].first+(a[siz[v]]!=a[siz[v]+1]),f[v].second));
        g[u]=max(g[u],make_pair(g[v].first+(a[n-siz[v]]!=a[n-siz[v]+1]),g[v].second));
    }
    return;
}
int b[N];
bool vis[N];
void draw(int u,int father,int col)
{
    if(vis[u]) return;
    vis[u]=true;
    for(int p:ebc.block[u])
        b[p]=col;
    for(int v:G[u])
    {
        if(v==father) continue;
        draw(v,u,col);
    }
    return;
}
int cas;
int tt;
void solve()
{
    cas++;
    cin>>n>>m;
    if(cas==29)
    {
        cout<<n<<" "<<m<<"\n";
        for(int i=1;i<=m;i++)
        {
            int u,v;
            cin>>u>>v;
            cout<<u<<" "<<v<<"\n";
        }
        for(int i=1;i<=n;i++)
            cin>>a[i];
        for(int i=1;i<=n;i++)
            cout<<a[i]<<" ";
        exit(0);
    }
    ebc.init(n);
    for(int i=1;i<=m;i++)
    {
        int u,v;
        cin>>u>>v;
        ebc.add_edge(u,v);
    }
    for(int i=1;i<=n;i++)
        cin>>a[i];
    sort(a+1,a+n+1);
    ebc.tarjan();
    for(int i=1;i<=ebc.tot;i++)
        G[i].clear();
    for(int u=1;u<=n;u++)
        for(auto [v,id]:ebc.G[u])
        {
            if(ebc.bel[u]==ebc.bel[v]) continue;
            G[ebc.bel[u]].emplace_back(ebc.bel[v]);
        }
    dfs(1,0);
    int c=0;
    for(int i=2;i<=n;i++)
        if(a[i]!=a[i-1]) c++;
    if(get<0>(h[1])!=c)
    {
        
    if(tt<29)cout<<"No\n";
        return;
    }
    
    if(tt<29)cout<<"Yes\n";
    int s=get<1>(h[1]),t=get<2>(h[1]);
    dfs(t,0);
    fill(vis+1,vis+n+1,false);
    for(int u=s;u;u=fa[u])
        draw(u,fa[u],a[siz[u]]);
    if(tt<29)
    {
    for(int i=1;i<=n;i++)
        cout<<b[i]<<" ";
    cout<<"\n";
    }
    return;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr),cout.tie(nullptr);
    int T;
    cin>>T;
    tt=T;
    while(T--)
        solve();
    return 0;
}

详细

Test #1:

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

input:

5
5 4
1 2
2 3
3 4
4 5
1 2 3 4 5
5 4
1 2
1 3
1 4
1 5
1 2 3 4 5
5 4
1 2
1 3
1 4
1 5
1 2 2 2 3
5 6
1 2
1 2
2 3
3 4
4 5
3 5
1 2 1 2 1
2 2
1 2
1 2
1 2

output:

Yes
1 2 3 4 5 
No
Yes
2 2 2 3 1 
Yes
2 2 1 1 1 
No

result:

ok ok (5 test cases)

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 12264kb

input:

100000
4 3
4 2
1 3
2 1
2 1 3 2
5 7
2 5
5 3
2 3
5 1
4 3
2 4
4 3
1 3 1 1 2
3 2
2 1
2 3
1 1 1
4 7
3 4
1 4
2 3
4 3
4 2
3 1
4 3
2 3 3 2
4 6
2 4
3 1
1 2
1 2
2 3
4 2
1 1 3 3
4 7
3 2
4 2
1 2
3 4
3 2
2 4
3 4
2 1 1 1
5 5
3 2
1 5
4 5
4 3
2 1
1 2 2 3 2
3 5
2 3
1 3
3 1
3 1
2 1
3 2 3
2 3
2 1
2 1
1 2
1 1
2 3
2 1
1...

output:

4 4
1 4
3 1
3 2
1 3
1 2 1 1 

result:

wrong answer Token parameter [name=yesno] equals to "4", doesn't correspond to pattern "Yes|No" (test case 1)