Submission #824276

#TimeUsernameProblemLanguageResultExecution timeMemory
824276AlphaMale06Bosses (BOI16_bosses)C++14
100 / 100
841 ms900 KiB
#include <bits/stdc++.h> #define pb push_back using namespace std; const int N=5005; vector<int> adj[N]; vector<int> adj1[N]; bool mark[N]; int ans=0; int cnt=0; int dfs(int node, int p){ int ret=1; for(auto to : adj1[node]){ if(to!=p){ ret+=dfs(to, node); } } ans+=ret; return ret; } void bfs(int node){ mark[node]=true; cnt=1; int sum=1; queue<int> q; q.push(node); while(!q.empty()){ int nd=q.front(); for(auto to : adj[nd]){ if(!mark[to]){ q.push(to); mark[to]=true; adj1[nd].pb(to); cnt++; } } q.pop(); } dfs(node, -1); } void clearmark(int n){ for(int i=1; i<= n; i++){ mark[i]=0; adj1[i].clear(); } } int main() { int n; cin >> n; for(int i=0; i< n; i++){ int k; cin >> k; for(int j=0; j< k; j++){ int kita; cin >> kita; adj[kita].pb(i+1); } } int mn=1e9; for(int i=1; i<=n; i++){ bfs(i); if(cnt==n)mn=min(mn, ans); clearmark(n+1); ans=0; } cout << mn << '\n'; }

Compilation message (stderr)

bosses.cpp: In function 'void bfs(int)':
bosses.cpp:26:9: warning: unused variable 'sum' [-Wunused-variable]
   26 |     int sum=1;
      |         ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...