제출 #35325

#제출 시각아이디문제언어결과실행 시간메모리
35325nickyrioBosses (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]; void dfs(int u) { d[u] = 1; for (int v : e[u]) if (p[v] == u) { dfs(v); d[u] += d[v]; } } long long bfs(int s) { FOR(i, 1, n) p[i] = 0; p[s] = -1; q.push(s); while (!q.empty()) { int u = q.front(); q.pop(); for (int v : e[u]) if (p[v] == 0) { p[v] = u; q.push(v); } } dfs(s); long long ans = 0; FOR(i, 1, n) ans += d[i]; 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...