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 STIZE(x) fprintf(stderr, "STIZE%d\n", x);
#define PRINT(x) fprintf(stderr, "%s = %d\n", #x, x);
#define NL(x) printf("%c", " \n"[(x)]);
#define lld long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define endl '\n'
#define mid (l+r)/2
#define all(a) begin(a),end(a)
#define sz(a) int((a).size())
#define LINF 1000000000000000000LL
#define INF 1000000000
#define EPS 1e-9
using namespace std;
#define MAXN 5010
vector<int> adj[MAXN];
lld dist[MAXN], n;
bool pos[MAXN];
queue<int> q;
lld BFS(int st) {
for(int i = 1; i <= n; i++) pos[i] = 0;
q.push(st);
pos[st] = true; dist[st] = 1;
while(!q.empty()) {
int v = q.front(); q.pop();
for(auto x : adj[v]) {
if(!pos[x]) {
dist[x] = dist[v] + 1; pos[x] = true;
q.push(x);
}
}
}
lld rez = 0;
for(int i = 1; i <= n; i++) {
if(!pos[i]) return LINF;
rez += dist[i];
}
return rez;
}
int main() {
//ios::sync_with_stdio(false);cin.tie(0);
cin >> n;
for(int i = 1; i <= n; i++) {
int k; cin >> k;
for(int j = 1; j <= k; j++) {
int x; cin >> x;
adj[x].pb(i);
}
}
lld rez = LINF;
for(int i = 1; i <= n; i++) {
rez = min(rez, BFS(i));
}
cout << rez;
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... |