# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
450398 | 2021-08-02T18:06:32 Z | Hamed5001 | Bosses (BOI16_bosses) | C++14 | 3 ms | 1560 KB |
#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(); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 1560 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 1560 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 1560 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |