이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int n, k, ne, head[5005], nxt[10005], to[10005], m, child[5005], mx, mxparent, d[5005], nextt[10005], tt[10005], ans;
bool vis[5005];
priority_queue <pair <int, int> > pq;
void AddEdge(int f, int t)
{
nxt[ne] = head[f];
to[ne] = t;
head[f] = ne++;
}
int DFS(int u)
{
// if(vis[u]) return 0;
vis[u] = 1;
int e = 0;
for(int j = d[u]; ~j; j = nextt[j])
{
//cout << ;
if(!vis[tt[j]])
{
e += DFS(tt[j]);
}
}
ans += e;
// cout << u << ' ' << e << '\n';
return e + 1;
}
void Addedge(int f, int t)
{
nextt[ne] = d[f];
tt[ne] = t;
d[f] = ne++;
}
int main()
{
//freopen("in.txt", "r", stdin);
scanf("%d", &n);
memset(head, -1, sizeof head);
for(int i = 0; i < n; i++)
{
scanf("%d", &k);
for(int j = 0; j < k; j++)
{
scanf("%d", &m);
AddEdge(m, i + 1);
child[m]++;
if(child[m] > mx)
{
mx = child[m];
mxparent = m;
}
}
}
pq.push({0, mxparent});
vis[mxparent] = 1;
ne = 0;
memset(d, -1, sizeof(d));
while(!pq.empty())
{
int x = pq.top().first, y = pq.top().second;
pq.pop();
for(int g = head[y]; ~g; g = nxt[g])
{
if(!vis[to[g]])
{
pq.push({x - 1, to[g]});
vis[to[g]] = 1;
Addedge(y, to[g]);
}
}
}
memset(vis, 0, sizeof(vis));
printf("%d\n", DFS(mxparent) + ans);
}
컴파일 시 표준 에러 (stderr) 메시지
bosses.cpp: In function 'int main()':
bosses.cpp:39:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
39 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
bosses.cpp:43:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
43 | scanf("%d", &k);
| ~~~~~^~~~~~~~~~
bosses.cpp:46:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
46 | scanf("%d", &m);
| ~~~~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |