Submission #1008508

#TimeUsernameProblemLanguageResultExecution timeMemory
1008508vjudge1Bosses (BOI16_bosses)C++17
0 / 100
1 ms604 KiB
#include <bits/stdc++.h> #define suiii ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define ll long long #define co cout<< // #pragma GCC optimize("O3,Ofast,unroll-loops") // #pragma GCC target("avx2,sse3,sse4,avx") using namespace std; //stuff vector<ll>v[5005]; vector<ll>v1[5005]; ll n; ll vis[5005]; pair<ll,ll>dfs(ll x,ll last){ ll ans=1; ll ans1=0; for(auto i:v1[x]){ if(i==last) continue; pair<ll,ll>a=dfs(i,x); ans+=a.first; ans1+=a.second; } ans1+=ans; return {ans,ans1}; } ll bfs(ll x){ memset(vis,0,sizeof(vis)); for(int i=0;i<=n;i++) v1[i].clear(); ll ans=0; queue<ll>q; q.push(x); while(q.size()){ ll idx=q.front(); q.pop(); if(vis[idx]) continue; vis[idx]=1; for(auto i:v[idx]){ if(vis[i]) continue; v1[idx].push_back(i); q.push(i); } } memset(vis,0,sizeof(vis)); return dfs(x,0).second; } void solve(){ cin>>n; ll ans=1e18; for(int i=1;i<=n;i++){ ll k; cin>>k; for(int j=0;j<k;j++){ ll b; cin>>b; v[b].push_back(i); } } for(int i=1;i<=n;i++){ ans=min(ans,bfs(i)); } co ans; } int main() { suiii int t=1; // cin>>t; while(t--){ solve(); } return 0; }

Compilation message (stderr)

bosses.cpp: In function 'long long int bfs(long long int)':
bosses.cpp:29:8: warning: unused variable 'ans' [-Wunused-variable]
   29 |     ll ans=0;
      |        ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...