Submission #1276327

#TimeUsernameProblemLanguageResultExecution timeMemory
1276327SmuggingSpunBosses (BOI16_bosses)C++20
100 / 100
375 ms732 KiB
#include<bits/stdc++.h> #define taskname "A" using namespace std; const int lim = 5e3 + 5; template<class T>void minimize(T& a, T b){ if(a > b){ a = b; } } int n, ans = INT_MAX; vector<int>g[lim]; void bfs(int s){ vector<int>h(n + 1, 0); queue<int>q; q.push(s); h[s] = 1; while(!q.empty()){ int u = q.front(); q.pop(); for(int& v : g[u]){ if(h[v] == 0){ h[v] = h[u] + 1; q.push(v); } } } if(*min_element(h.begin() + 1, h.end()) > 0){ minimize(ans, accumulate(h.begin(), h.end(), 0)); } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if(fopen(taskname".inp", "r")){ freopen(taskname".inp", "r", stdin); } cin >> n; for(int i = 1; i <= n; i++){ int k; cin >> k; for(int j = 0; j < k; j++){ int x; cin >> x; g[x].push_back(i); } } for(int i = 1; i <= n; i++){ bfs(i); } cout << ans; }

Compilation message (stderr)

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