이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e3+10;
int n, pai[MAXN], nivel[MAXN], ans[MAXN];
bool mark[MAXN];
vector<int> grafo[MAXN];
int BFS(int u)
{
memset(mark, 0, sizeof mark);
memset(ans, 0, sizeof ans);
queue<int> fila;
vector<int> level[MAXN];
fila.push(u), mark[u] = 1, nivel[u] = 0;
int qtd = 1, maxniv = 0, k = 0;
while (!fila.empty())
{
int x = fila.front();
fila.pop();
for (int i = 0; i < grafo[x].size(); i++)
{
int v = grafo[x][i];
if (mark[v]) continue;
pai[v] = x, nivel[v] = nivel[x]+1;
level[nivel[v]].push_back(v);
maxniv = max(maxniv, nivel[v]);
mark[v] = 1, fila.push(v);
qtd++;
}
}
if (qtd < n) return 1000000000;
for (int i = maxniv; i > 0; i--)
{
for (int j = 0; j < level[i].size(); j++)
{
int v = level[i][j];
ans[v]++;
ans[pai[v]] += ans[v];
k += ans[v];
}
}
k += ans[u]+1;
return k;
}
int main(void)
{
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++)
{
int m;
cin >> m;
while (m--)
{
int u;
cin >> u;
grafo[u].push_back(i);
}
}
int out = 1e9;
for (int i = 1; i <= n; i++)
out = min(out, BFS(i));
cout << out << "\n";
}
컴파일 시 표준 에러 (stderr) 메시지
bosses.cpp: In function 'int BFS(int)':
bosses.cpp:24:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < grafo[x].size(); i++)
~~^~~~~~~~~~~~~~~~~
bosses.cpp:41:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < level[i].size(); j++)
~~^~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |