Submission #1057156

#TimeUsernameProblemLanguageResultExecution timeMemory
1057156vjudge1Bosses (BOI16_bosses)C++17
100 / 100
507 ms1112 KiB
#include <bits/stdc++.h> using namespace std; using i64 = long long; const i64 oo64 = 2e18; const int MAXN = 5e3 + 5; int N; vector<int> adj[MAXN]; vector<int> g[MAXN]; int dist[MAXN]; i64 ans = oo64; void BFS(int r) { for(int i = 1; i <= N; i++) { g[i].clear(); dist[i] = N + 1; } queue<int> Q; Q.emplace(r); dist[r] = 1; while(!Q.empty()) { int u = Q.front(); Q.pop(); for(int v : adj[u]) { if(dist[v] > dist[u] + 1) { g[u].emplace_back(v); dist[v] = dist[u] + 1; Q.emplace(v); } } } i64 res = 0; for(int i = 1; i <= N; i++) { if(dist[i] > N) return; res += dist[i]; } ans = min(ans, res); } signed main() { #define TASK "code" if (fopen(TASK ".inp", "r")) { freopen(TASK ".inp", "r", stdin); freopen(TASK ".out", "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N; for(int i = 1; i <= N; i++) { int sz = 0; cin >> sz; for(int j = 1; j <= sz; j++) { int x = 0; cin >> x; adj[x].emplace_back(i); } } for(int i = 1; i <= N; i++) BFS(i); cout << ans; return (0 ^ 0); }

Compilation message (stderr)

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