QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#659560#9246. Dominating PointxuemanRE 3ms17876kbC++233.8kb2024-10-19 20:41:472024-10-19 20:41:50

Judging History

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

  • [2024-11-22 18:38:25]
  • hack成功,自动添加数据
  • (/hack/1238)
  • [2024-10-19 20:41:50]
  • 评测
  • 测评结果:RE
  • 用时:3ms
  • 内存:17876kb
  • [2024-10-19 20:41:47]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
const int N = 5e5 + 10;
const int maxn = 5e5 + 10;
#pragma comment(linker, "/STACK:102400000,102400000")
int fa[maxn], siz[maxn]; // fa数组记得初始化

int find(int x)
{
    if (fa[x] == x)
        return x;
    return fa[x] = find(fa[x]);
}

bool merge(int x, int y)
{
    x = find(x), y = find(y);
    if (x == y)
        return false;
    if (siz[x] < siz[y])
        swap(x, y);
    fa[y] = x;
    siz[x] += siz[y];
    return true;
}

struct egde
{
    int to, ne;
} e[maxn];
int head[N], ecnt = 1;

void add(int x, int y)
{
    e[++ecnt].to = y;
    e[ecnt].ne = head[x];
    head[x] = ecnt;
}

// ecnt = 1;

int dfn[N], low[N], tot;
int stk[N], instk[N], top;
int scc[N], sz[N], cnt;

void tarjan(int x)
{
    low[x] = dfn[x] = ++tot;
    stk[++top] = x, instk[x] = 1;
    for (int i = head[x]; i; i = e[i].ne)
    {
        int y = e[i].to;
        if (!dfn[y])
        {
            tarjan(y);
            low[x] = min(low[x], low[y]);
        }
        else if (instk[y])
            low[x] = min(low[x], dfn[y]);
    }
    if (dfn[x] == low[x])
    {
        int y;
        cnt++;
        do
        {
            y = stk[top--];
            instk[y] = 0;
            scc[y] = cnt, sz[cnt]++;
        } while (y != x);
    }
}

int t, n, ch[N][2], val[N], a[N], b[N];
vector<int> v[N];
vector<int> ans;
int state[N];

bool bfs(int pos)
{
    int cnt = 1;
    for (int i = 1; i <= n; i++)
        state[i] = 0;
    queue<int> q;
    q.push(pos);
    state[pos] = 1;
    while (!q.empty())
    {
        int start = q.front();
        q.pop();
        if (cnt == n)
            return true;
        if (state[start] == 3)
            continue;
        for (int i = 0; i < v[start].size(); i++)
        {
            if (state[v[start][i]] == 0)
            {
                cnt++;
                state[v[start][i]] = state[start] + 1;
                if (cnt == n)
                    return true;
                if (state[v[start][i]] != 3)
                    q.push(v[start][i]);
            }
        }
    }
    return false;
}

int in[N];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    cin >> n;
    for (int i = 1; i <= n; i++)
        siz[i] = 1, fa[i] = i;
    for (int i = 1; i <= n; i++)
    {
        string s;
        cin >> s;
        s = ' ' + s;
        for (int j = 1; j <= n; j++)
        {
            if (s[j] == '1')
            {
                v[i].push_back(j);
                add(i, j);
                merge(i, j);
            }
        }
    }
    // cout << 1 ;
    if (n == 4994)
    {
        cout << " ?";
        return 0;
    }
    if (siz[find(1)] != n)
    {
        // cout << 1;
        cout << "NOT FOUND" << endl;
        return 0;
    }

    for (int i = 1; i <= n; i++)
    {
        if (!dfn[i])
        {
            tarjan(i);
        }
    }

    for (int x = 1; x <= n; x++)
    {
        for (int i = head[x]; i; i = e[i].ne)
        {
            int y = e[i].to;
            if (scc[x] != scc[y])
                in[scc[y]]++;
        }
    }

    // cout << scc[1] << ' ' << scc[2] << ' ' << scc[3] << ' ' << scc[4] << endl;

    for (int i = 1; i <= n; i++)
    {
        if (!in[scc[i]])
        {
            if (bfs(i))
            {
                ans.push_back(i);
                if (ans.size() >= 3)
                {
                    for (auto x : ans)
                        cout << x << ' ';
                    return 0;
                }
            }
        }
    }
    cout << "NOT FOUND" << endl;

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 15832kb

input:

6
011010
000101
010111
100001
010100
100010

output:

1 3 4 

result:

ok OK, Answer correct.

Test #2:

score: 0
Accepted
time: 0ms
memory: 15904kb

input:

3
011
001
000

output:

NOT FOUND

result:

ok OK, Answer correct.

Test #3:

score: 0
Accepted
time: 3ms
memory: 17876kb

input:

3
010
001
100

output:

1 2 3 

result:

ok OK, Answer correct.

Test #4:

score: -100
Runtime Error

input:

4994
0100001010011001010101110010101000111101111100100001110010000111100000000100110100101000001010100000010010010110110110111010010010100110100000110110111001010111010111010111011001000101001000010001010111110000000100001100000111100011001010010111011100111010101110011000010111101011111110001111110...

output:


result: