This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define int long long
#define pb push_back
using namespace std;
const int maxn = 5000 + 10;
int n, h[maxn];
bool mark[maxn];
vector <int> adj[maxn];
queue <int> q;
int32_t main (){
ios_base::sync_with_stdio(0);
cin >> n;
for (int x, i = 1; i <= n; i++){
cin >> x;
for (int y, j = 0; j < x; j++)
cin >> y,
adj[y].pb(i);
}
int ans = 0;
for (int i = 1; i <= n; i++){
q.push(i), mark[i] = 1, h[i] = 1;
int tmp = 0;
while (q.size()){
int v = q.front(); q.pop();
tmp += h[v];
for (auto u : adj[v]){
if (!mark[u]){
h[u] = h[v] + 1;
q.push(u);
mark[u] = 1;
}
}
}
ans = max(ans, tmp);
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |