제출 #994140

#제출 시각아이디문제언어결과실행 시간메모리
994140SharkyBosses (BOI16_bosses)C++17
0 / 100
0 ms600 KiB
#include <bits/stdc++.h> using namespace std; const int N = 5001; vector<int> adj[N]; int sz[N], ans = 0, opt = 1e9; bool vis[N]; void dfs(int u) { vis[u] = true; sz[u] = 1; for (auto& v : adj[u]) { if (!vis[v]) { dfs(v); sz[u] += sz[v]; } } ans += sz[u]; } int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for (int i = 1, j, x; i <= n; i++) { cin >> j; while (j--) { cin >> x; adj[x].push_back(i); } } for (int rt = 1; rt <= n; rt++) { ans = 0; for (int j = 1; j <= n; j++) vis[j] = 0, sz[j] = 0; dfs(rt); opt = min(opt, ans); } cout << opt << '\n'; } // 1 // 2 3 // 456 78 // 8 // 4 3 // 1 1 1 1 1 // find sigma(sz[u])
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...