Submission #813750

#TimeUsernameProblemLanguageResultExecution timeMemory
813750burythelightdeepwithinBosses (BOI16_bosses)C++14
0 / 100
0 ms468 KiB
#include <bits/stdc++.h> using namespace std; const int N = 5003; vector <int> adj[N], adj2[N]; int vs[N], sz[N], ans, tmp = 1e9+7, n; queue <int> q; void bfs(){ while(!q.empty()){ int u = q.front(); vs[u] = 1; //cout << "BFS " << u << endl; q.pop(); for (auto v: adj[u]){ if (!vs[v]){ q.push(v); adj2[u].push_back(v); vs[v] = 1; } } } //cout << endl; } void dfs(int u, int par){ sz[u]++; for (auto v: adj2[u]){ if (v != par){ dfs(v, u); sz[u] += sz[v]; } } ans += sz[u]; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 1; i <= n; i++){ int m; cin >> m; for (int j = 1; j <= m; j++){ int x; cin >> x; adj[x].push_back(i); } } for (int i = 1; i <= n; i++){ for (int j = 1; j <= n; j++){ vs[j] = 0; adj2[j].clear(); } q.push(i); bfs(); ans = 0; dfs(i, i); tmp = min(tmp, ans); } cout << tmp; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...