QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#586308#7798. Colorful Villagephuong2222Compile Error//C++142.7kb2024-09-24 10:43:062024-09-24 10:43:08

Judging History

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

  • [2024-09-24 10:43:08]
  • 评测
  • [2024-09-24 10:43:06]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using lli = long long;
const int maxN = 4e5 + 5;
int n,a[maxN],scc,id[maxN];
int num[maxN],low[maxN],t,res[maxN];
vector<int> adj[maxN],adj1[maxN];
vector<int> q;
vector<int> e[maxN];
inline o(int x)
{
    return x + 2 * n;
}
void reset()
{
    scc = 0;t = 0;
    for (int i = 0;i <= 4 * n;++i)
    {
        adj1[i].clear();res[i] = 0;
        id[i] = num[i] = low[i] = 0;
    }
    q.clear();
}
void input()
{
    cin >> n;
    reset();
    for (int i = 1;i <= 2 * n;++i) {adj[i].clear();e[i].clear();}
    for (int i = 1;i <= 2 * n;++i)
    {
        cin >> a[i];
        e[a[i]].push_back(i);
    }
    for (int i = 1;i < 2 * n;++i)
    {
        int u,v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
}
void add(int u,int v)
{
    adj1[o(-u)].push_back(o(v));
    adj1[o(-v)].push_back(o(u));
}
void dfs(int u,int par)
{
    if (par != 0) add(-u,par);
    else add(u,u);
    for (int v : adj[u])
    {
        if (v == par) continue;
        dfs(v,u);
    }
}
void dfs1(int u)
{
    num[u] = low[u] = ++t;
    q.push_back(u);
    for (int v : adj1[u])
    {
        if (num[v] == -1) continue;
        if (num[v] == 0)
        {
            dfs1(v);
            low[u] = min(low[u],low[v]);
        }
        else low[u] = min(low[u],num[v]);
    }
    if (low[u] == num[u])
    {
        ++scc;
        int v;
        do
        {
            v = q.back();q.pop_back();
            num[v] = -1;
            id[v] = scc;
        }
        while (v != u);
    }
}
bool calc(int u)
{
    dfs(u,0);
    for (int i = 1;i <= n;++i)
    {
        int u = e[i][0];
        int v = e[i][1];
        add(u,v);
        add(-u,-v);
    }
    for (int i = 0;i <= 4 * n;++i)
        if (num[i] == 0) dfs1(i);
    //for (int i = 1;i <= 2 * n;++i) cout << id[o(-i)] << " " << id[o(i)] << " "  << i << "\n";
    for (int i = 1;i <= 2 * n;++i)
    {
        if (id[o(-i)] == id[o(i)]) return false;
        res[i] = id[o(-i)] > id[o(i)];
    }
    return true;
}
void solve()
{
    if (calc(e[1][0]))
    {
        for (int i = 1;i <= 2 * n;++i) if (res[i]) cout << i << " ";
        cout << "\n";
    }
    else
    {
        reset();
        if (calc(e[1][1]))
        {
            for (int i = 1;i <= 2 * n;++i) if (res[i]) cout << i << " ";
            cout << "\n";
        }
        else cout << -1 << "\n";
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen("P4.inp","r",stdin);
    //freopen("P4.out","w",stdout);
    int t;
    cin >> t;
    while(t--)
    {
        input();
        solve();
    }
}

详细

answer.code:10:8: error: ISO C++ forbids declaration of ‘o’ with no type [-fpermissive]
   10 | inline o(int x)
      |        ^