Submission #450398

#TimeUsernameProblemLanguageResultExecution timeMemory
450398Hamed5001Bosses (BOI16_bosses)C++14
0 / 100
3 ms1560 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(); }

Compilation message (stderr)

bosses.cpp: In function 'int main()':
bosses.cpp:54:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |  freopen("input.txt", "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
bosses.cpp:55:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |  freopen("output.txt", "w", stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...