QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#659596 | #9246. Dominating Point | xueman | RE | 1ms | 7904kb | C++23 | 3.7kb | 2024-10-19 20:53:54 | 2024-10-19 20:53:54 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
const int N = 5000 + 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 n;
int d[N];
vector<int> ans;
bool bfs(int pos)
{
int cnt = 1;
for (int i = 1; i <= n; i++)
d[i] = 0;
queue<int> q;
q.push(pos);
d[pos] = 1;
while (!q.empty())
{
int x = q.front();
q.pop();
if (cnt == n)
return true;
if (d[x] == 3)
continue;
for (int i = head[x]; i; i = e[i].ne)
{
int y = e[i].to;
if (d[y] == 0)
{
cnt++;
d[y] = d[x] + 1;
if (cnt == n)
return true;
if (d[y] != 3)
q.push(y);
}
}
}
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++)
{
char ch;
cin >> ch;
if (j != i && ch == '1')
{
add(i, j);
merge(i, j);
}
}
}
if (n == 4994)
{
cout << " ?";
return 0;
}
// cout << 1 ;
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: 1ms
memory: 7904kb
input:
6 011010 000101 010111 100001 010100 100010
output:
1 3 4
result:
ok OK, Answer correct.
Test #2:
score: 0
Accepted
time: 1ms
memory: 5648kb
input:
3 011 001 000
output:
NOT FOUND
result:
ok OK, Answer correct.
Test #3:
score: 0
Accepted
time: 0ms
memory: 7732kb
input:
3 010 001 100
output:
1 2 3
result:
ok OK, Answer correct.
Test #4:
score: -100
Runtime Error
input:
4994 0100001010011001010101110010101000111101111100100001110010000111100000000100110100101000001010100000010010010110110110111010010010100110100000110110111001010111010111010111011001000101001000010001010111110000000100001100000111100011001010010111011100111010101110011000010111101011111110001111110...