제출 #1050221

#제출 시각아이디문제언어결과실행 시간메모리
1050221manhlinh1501Bosses (BOI16_bosses)C++17
100 / 100
853 ms1116 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 dp[MAXN]; i64 ans = oo64; void DFS(int u) { dp[u] = 1; for(int v : g[u]) { DFS(v); dp[u] += dp[v]; } } 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); } } } for(int i = 1; i <= N; i++) if(dist[i] > N) return; DFS(r); ans = min(ans, accumulate(dp + 1, dp + N + 1, 0LL)); } 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); }

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

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