Submission #450399

#TimeUsernameProblemLanguageResultExecution timeMemory
450399Hamed5001Bosses (BOI16_bosses)C++14
0 / 100
1 ms1484 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int mxN = 5e4+10; int n; vector<int> adj[mxN]; int bfs(int st) { vector<bool> vis(n+10, 0); queue<pair<int ,int>> q; q.push({1, st}); int ret = 0; vis[st] = 1; while(q.size()) { auto node = q.front(); ret += node.first; vis[node.second] = 1; q.pop(); for (auto it : adj[node.second]) { if (!vis[it]) { q.push({node.first+1, it}); } } } return ret; } void solve() { cin >> n; for (int u = 1; u <= n; u++) { int k; cin >> k; for (int j = 0; j < k; j++) { int v; cin >> v; adj[v].push_back(u); } } int ans = INT_MAX; for (int i = 1; i <= n; i++) { ans = min(ans, bfs(i)); } cout << ans; } int main() { // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif ios_base::sync_with_stdio(false); cin.tie(0); solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...