Submission #35327

#TimeUsernameProblemLanguageResultExecution timeMemory
35327nickyrioBosses (BOI16_bosses)C++14
0 / 100
0 ms2196 KiB
#include <bits/stdc++.h> #define FOR(i, a, b) for (int i = a; i<=b ; i++) #define FORD(i, a, b) for (int i = a; i>=b; i--) #define REP(i, a) for (int i = 0; i<a; i++) #define N 5050 #define pp pair<int, int> #define IO cin.tie(NULL);cout.tie(NULL); #define bit(S, i) (((S) >> i) & 1) template<typename T> inline void read(T &x) { char c; bool neg = false; while (!isdigit(c = getchar()) && c != '-'); x = 0; if (c == '-') { neg = true; c = getchar(); } do { x = x * 10 + c - '0'; } while (isdigit(c = getchar())); if (neg) x = -x; } template<typename T> inline void write(T x) { if (x < 0) { putchar('-'); write(-x);return; } if (x < 10) { putchar(char(x + 48)); } else { write(x/10); putchar(char(48 + x%10)); } } template<typename T> inline void writeln(T x) { write(x); putchar('\n'); } using namespace std; int n, k, u, p[N]; vector<int> e[N]; queue<int> q; long long d[N]; long long bfs(int s) { FOR(i, 1, n) p[i] = 0; p[s] = -1; d[s] = 1; q.push(s); long long ans = 0; while (!q.empty()) { int u = q.front(); q.pop(); ans += d[u]; for (int v : e[u]) if (p[v] == 0) { p[v] = u; d[v] = d[u] + 1; q.push(v); } } return ans; } int main() { IO; read(n); FOR(i, 1, n) { read(k); while (k--) { read(u); e[u].push_back(i); } } long long ans = 1e18; FOR(i, 1, n) ans = min(ans, bfs(i)); writeln(ans); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...