Submission #725132

#TimeUsernameProblemLanguageResultExecution timeMemory
725132bufferingBosses (BOI16_bosses)C++17
100 / 100
624 ms656 KiB
#include <bits/stdc++.h> using namespace std; void IO(string s = "") { if (s == "") { freopen("input.txt", "r", stdin); freopen("output 2.txt", "w", stdout); } if (s != "") { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } } int main() { ios::sync_with_stdio(false); cin.tie(0); //IO(); int n; cin >> n; vector<vector<int>> adj(n); for (int i = 0; i < n; i++) { int m; cin >> m; for (int j = 0; j < m; j++) { int v; cin >> v; v--; adj[v].push_back(i); } } long long ans = 1e9; for (int i = 0; i < n; i++) { vector<int> depths(n, -1); queue<int> q; q.push(i); depths[i] = 0; while (!q.empty()) { int node = q.front(); q.pop(); for (int v: adj[node]) { if (depths[v] == -1) { depths[v] = depths[node] + 1; q.push(v); } } } if (*min_element(depths.begin(), depths.end()) == 0) { long long curr = n; for (auto d: depths) curr += d; ans = min(ans, curr); } } cout << ans << endl; }

Compilation message (stderr)

bosses.cpp: In function 'void IO(std::string)':
bosses.cpp:8:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |         freopen("input.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
bosses.cpp:9:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |         freopen("output 2.txt", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bosses.cpp:13:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |         freopen((s + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bosses.cpp:14:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |         freopen((s + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...