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>
using namespace std;
const int INF = 1e9;
const int MAXN = 5e3;
int N;
vector<int> children[MAXN + 5];
bool vis[MAXN + 5];
int dfs(int cur, int depth) {
vis[cur] = true;
int ans = depth;
for (auto child: children[cur]) {
if (vis[child]) continue;
ans += dfs(child, depth + 1);
}
return ans;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> N;
for (int i = 0; i < N; i++) {
int sz; cin >> sz;
while (sz--) {
int u; cin >> u; u--;
children[i].push_back(u);
}
}
int ans = INF;
for (int i = 0; i < N; i++) {
memset(vis, false, sizeof vis);
ans = min(ans, dfs(i, 1));
}
cout << ans << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |