제출 #657175

#제출 시각아이디문제언어결과실행 시간메모리
657175quocnguyen1012Bosses (BOI16_bosses)C++14
100 / 100
626 ms664 KiB
#include "bits/stdc++.h" using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen("input.txt", "r")) freopen("input.txt", "r", stdin); int n; cin >> n; vector<vector<int>> adj(n + 5); for (int i = 1; i <= n; ++i) { int k; cin >> k; while (k--) { int v; cin >> v; // adj[i].emplace_back(v); adj[v].emplace_back(i); } } vector<int> d(n + 5, -1); int ans = INT_MAX; for (int r = 1; r <= n; ++r) { queue<int> Q; fill(d.begin(), d.end(), -1); int tot = 0; for (d[r] = 1, Q.push(r); !Q.empty(); ) { int u = Q.front(); Q.pop(); for (int v : adj[u]) { if (d[v] == -1) { d[v] = d[u] + 1; Q.push(v); } } } bool bad = false; for (int i = 1; i <= n; ++i) { tot += d[i]; if (d[i] == -1) bad = true; } if (not bad) ans = min(ans, tot); } cout << ans; }

컴파일 시 표준 에러 (stderr) 메시지

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