제출 #994142

#제출 시각아이디문제언어결과실행 시간메모리
994142SharkyBosses (BOI16_bosses)C++17
0 / 100
0 ms348 KiB
#include <bits/stdc++.h> using namespace std; const int N = 5001; vector<int> adj[N]; int sz[N], ans = 0, opt = 1e9, cnt = 0; bool vis[N]; void dfs(int u) { vis[u] = true; sz[u] = 1; cnt++; 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 = cnt = 0; for (int j = 1; j <= n; j++) vis[j] = 0, sz[j] = 0; dfs(rt); if (cnt == n) 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...