This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Pantyhose + glasses = infinity
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr << #x << " = " << x << '\n';
#define BP() cerr << "OK!\n";
#define PR(A, n) {cerr << #A << " = "; for (int _=1; _<=n; ++_) cerr << A[_] << ' '; cerr << '\n';}
#define PR0(A, n) {cerr << #A << " = "; for (int _=0; _<n; ++_) cerr << A[_] << ' '; cerr << '\n';}
#define FILE_NAME "data"
const int MAX_N = 5002;
const int64_t INF = 1e18;
int n, d[MAX_N];
vector<int> g[MAX_N];
void enter() {
cin >> n;
for (int i=1; i<=n; ++i) {
int k;
cin >> k;
while (k--) {
int u;
cin >> u;
g[u].push_back(i);
}
}
}
int64_t bfs(int st) {
queue<int> qu;
memset(d, 0, sizeof(d));
d[st] = 1;
qu.push(st);
int64_t res = 0;
while (qu.size()) {
int u = qu.front();
res += d[u];
qu.pop();
for (auto v : g[u]) {
if (d[v]==0) {
d[v] = d[u] + 1;
qu.push(v);
}
}
}
return res;
}
void solve() {
int64_t res = INF;
for (int u=1; u<=n; ++u)
res = min(res, bfs(u));
cout << res;
}
int main() {
#ifdef OFFLINE_JUDGE
freopen(FILE_NAME".inp", "r", stdin);
freopen(FILE_NAME".out", "w", stdout);
#endif
ios::sync_with_stdio(0); cin.tie(0);
enter();
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |