Submission #338066

#TimeUsernameProblemLanguageResultExecution timeMemory
338066theshadow_04Bosses (BOI16_bosses)C++11
67 / 100
1558 ms3128 KiB
// V T An #include <bits/stdc++.h> #define Task "BOSSES" #define pb push_back #define F first #define S second using namespace std; const int maxn = 50005; int n; vector<int> a[maxn], ke[maxn]; int dd[maxn]; int ans = 2e9, f[maxn]; queue<int> Q; void BFS(int s) { Q.push(s); dd[s] = 1; while(Q.size()) { int u = Q.front(); Q.pop(); for(auto v : a[u]) { if(!dd[v]) { dd[v] = 1; ke[u].pb(v); Q.push(v); } } } } void DFS(int u) { int sum = 0; for(auto v : ke[u]) { if(!f[v]) { DFS(v); sum += f[v]; } } f[u] = sum + 1; } void Solve(int u) { for(int i = 1; i <= n; ++ i) ke[i].clear(), f[i] = dd[i] = 0; BFS(u); DFS(u); int total = 0; for(int i = 1; i <= n; ++ i) { if(!f[i]) return; total += f[i]; } ans = min(ans, total); } int main() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); if(fopen(Task".inp", "r")) { freopen(Task".inp", "r", stdin); freopen(Task".out", "w", stdout); } cin >> n; for(int i = 1; i <= n; ++ i) { int k; cin >> k; while(k --) { int x; cin >> x; a[x].pb(i); } } for(int i = 1; i <= n; ++ i) { Solve(i); } cout << ans; } // CHY-AKAV

Compilation message (stderr)

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