Submission #947569

#TimeUsernameProblemLanguageResultExecution timeMemory
947569blacktulipBosses (BOI16_bosses)C++17
100 / 100
943 ms1144 KiB
#include <bits/stdc++.h> using namespace std; typedef long long lo; #define fi first #define se second #define endl "\n" #define int long long #define pb push_back #define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define FOR for(int i=1;i<=n;i++) #define mid ((start+end)/2) #define ort ((bas+son)/2) #define _ << " " << const lo inf = 1000000000; const lo li = 5005; const lo mod = 1000000007; int n,m,a[li],k,flag,t,dp[li],vis[li]; int cev; string s; vector<int> v[li],vv[li]; inline void dfs(int node,int ata){ dp[node]=1; for(auto go:vv[node]){ if(go==ata)continue; dfs(go,node); dp[node]+=dp[go]; } //~ cout<<node _ dp[node]<<endl; } int32_t main(void){ fio(); cin>>n; FOR{ cin>>k; for(int j=1;j<=k;j++){ int x; cin>>x; v[x].pb(i); } } cev=1000000000000000000; FOR{ queue<int> q; q.push(i); memset(vis,0,sizeof(vis)); for(int j=1;j<=n;j++)vv[j].clear(); int say=0; while(q.size()){ say++; int node=q.front(); q.pop(); vis[node]=1; for(auto go:v[node]){ if(vis[go])continue; vis[go]=1; vv[node].pb(go); q.push(go); } } if(say!=n){continue;} int sum=0; dfs(i,0); for(int j=1;j<=n;j++)sum+=dp[j]; cev=min(cev,sum); } cout<<cev<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...