Submission #994885

#TimeUsernameProblemLanguageResultExecution timeMemory
994885BaytoroBosses (BOI16_bosses)C++17
100 / 100
474 ms800 KiB
#include <bits/stdc++.h> using namespace std; #define fr first #define sc second #define pb push_back #define int long long #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() void fopn(string name){ freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout); } const int N=5005; vector<int> g[N]; int cnt[N]; int n; int bfs(int x){ vector<int> used(N); queue<pair<int,int> > dq; dq.push(make_pair(x,1)); int res=1; used[x]=1; while(!dq.empty()){ int k=dq.front().fr; int d=dq.front().sc; dq.pop(); for(auto it: g[k]){ if(!used[it]){ dq.push(make_pair(it,d+1)); res+=d+1; used[it]=1; } } } for(int i=1;i<=n;i++) if(!used[i]) return 1000000000; return res; } void solve(){ cin>>n; for(int i=1;i<=n;i++){ int k;cin>>k; for(int j=0;j<k;j++){ int x;cin>>x; g[x].pb(i); } } int ans=1e9; for(int i=1;i<=n;i++){ ans=min(ans,bfs(i)); } cout<<ans<<endl; } signed main(){ //fopn("paint"); int t=1;//cin>>t; while(t--) solve(); }

Compilation message (stderr)

bosses.cpp: In function 'void fopn(std::string)':
bosses.cpp:10:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |  freopen((name+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bosses.cpp:11:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |  freopen((name+".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...