QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#585430#7798. Colorful Village_laxWA 4ms30480kbC++203.4kb2024-09-23 20:48:092024-09-23 20:48:10

Judging History

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

  • [2024-09-23 20:48:10]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:30480kb
  • [2024-09-23 20:48:09]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000000007;
const ll N = 5e5 + 5;
#define bit(x,y) ((x >> y) & 1LL)
const ll inf = LLONG_MAX/5;
vector<ll> a[N];
vector<ll> p[N];
set<ll> a2[N];
vector<ll> haha[N];
vector<ll> c[N];
ll low[N],num[N],cnt,g[N],seen[N],cg;
void build(ll x, ll px)
{
    if(x != 1)
    {
        ll t = x * 2;
        ll pt = px * 2;
        ll ut = t - 1;
        ll upt = pt - 1;
        a[t].push_back(pt);
        a[upt].push_back(ut);
    }
    for(auto y : p[x])
    {
        if(y != px)
        {
            build(y,x);
        }
    }
}
stack<ll> st;
void scc(ll x)
{
    st.push(x);
    low[x] = num[x] = cnt++;
    for(auto y : a[x])
    {
        if(num[y] == 0)
        {
            scc(y);
            low[x] = min(low[x],low[y]);
        }else
        {
            if(g[y] == 0) low[x] = min(low[x],num[y]);
        }
    }
    if(num[x] == low[x])
    {
        g[x] = ++cg;
        haha[cg].push_back(x);
        while(st.top() != x)
        {
            g[st.top()] = g[x];
            haha[cg].push_back(st.top());
            st.pop();
        }
        st.pop();
    }
}
void mark(ll x)
{
    for(auto y : a2[x])
    {
        if(seen[y] == 0)
        {
            mark[y];
        }
    }
    if(seen[x] != 0) return;
    seen[x] = 1;
    for(auto y : a2[x])
    {
        if(seen[y] == -1) seen[x] = -1;
    }
    if(seen[x] == 1)
    {
        for(auto y : haha[x])
        {
            ll uy;
            if(y % 2 == 0) uy = y - 1;
            else uy = y + 1;
            seen[g[uy]] = -1;
        }
    }
}
void solve()
{
    ll n;
    cin >> n;
    ll i,j;
    for(i = 1;i <= 2 * n;i++)
    {
        ll tmp;
        cin >> tmp;
        c[tmp].push_back(i);
    }
    for(i = 1;i <= n;i++)
    {
        ll x = c[i][0];
        ll y = c[i][1];
        ll ux = 2 * x - 1;
        ll uy = 2 * y - 1;
        x = x * 2;
        y = y * 2;
        a[x].push_back(uy);
        a[uy].push_back(x);
        a[ux].push_back(y);
        a[y].push_back(ux);
    }
    for(i = 1;i <= 2 * n - 1;i++)
    {
        ll u,v;
        cin >> u >> v;
        p[u].push_back(v);
        p[v].push_back(u);
    }
    build(1,0);
    for(i = 1;i <= 4 * n;i++) if(g[i] == 0) scc(i);
    for(i = 1;i <= 2 * n;i++)
    {
        ll x = i * 2;
        ll ux = x - 1;
        if(g[x] == g[ux])
        {
            cout << -1 << "\n";
            return;
        }
    }
    for(i = 1;i <= cg;i++)
    {
        for(auto x : haha[i])
        {
            for(auto y : a[x])
            {
                if(g[y] != i) a2[i].insert(g[y]);
            }
        }
    }
    for(i = 1;i <= cg;i++)
    {
        if(seen[i] == 0)
        {
            mark(i);
        }
    }
    for(i = 1;i <= 2 * n;i++)
    {
        if(seen[g[i * 2]] == 1) cout << i << " ";
    }
    cout << "\n";
    for(i  = 1;i <= n * 4;i++)
    {
        a[i].clear();
        a2[i].clear();
        haha[i].clear();
        c[i].clear();
        p[i].clear();
        seen[i] = 0;
        low[i] = 0;
        num[i] = 0;
        g[i] = 0;
    }
    cnt = 0;
    cg = 0;
    return;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll t;
    cin >> t;
    while(t--)
    {
        solve();
    }
}

详细

Test #1:

score: 100
Accepted
time: 4ms
memory: 30476kb

input:

2
4
1 3 1 3 4 4 2 2
1 6
5 3
2 4
7 1
7 5
5 8
2 5
3
1 1 2 2 3 3
1 2
2 3
3 4
4 5
5 6

output:

1 2 5 7 
-1

result:

ok ok, 1 yes, 1 no (2 test cases)

Test #2:

score: 0
Accepted
time: 4ms
memory: 30440kb

input:

1
1
1 1
1 2

output:

1 

result:

ok ok, 1 yes, 0 no (1 test case)

Test #3:

score: -100
Wrong Answer
time: 4ms
memory: 30480kb

input:

5
1
1 1
2 1
1
1 1
2 1
3
3 2 3 1 1 2
4 1
6 1
3 5
5 1
2 4
4
3 3 1 1 4 4 2 2
2 7
7 6
1 2
8 1
4 2
2 5
3 1
1
1 1
1 2

output:

1 
1 
1 5 6 
-1
-1

result:

wrong answer jury found a solution but participant did not (test case 4)