Submission #450400

#TimeUsernameProblemLanguageResultExecution timeMemory
450400Hamed5001Bosses (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+1, 0); queue<pair<int ,int>> q; q.push({1, st}); int ret = 0; 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}); } } } for (int i = 1; i <= n; i++) { if (!vis[i]) { ret = INT_MAX; break; } } 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() { 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...