Submission #858320

#TimeUsernameProblemLanguageResultExecution timeMemory
8583208pete8Bosses (BOI16_bosses)C++14
100 / 100
415 ms832 KiB
#include<iostream> #include<stack> #include<map> #include<vector> #include<string> #include<unordered_map> #include <queue> #include<cstring> #include<limits.h> #include<cmath> #include<set> #include<algorithm> #include<bitset> #include<list> using namespace std; #define ll long long #define f first #define endl "\n" #define s second #define pii pair<int,int> #define ppii pair<int,pii> #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define F(n) for(int i=0;i<n;i++) #define lb lower_bound #define ub upper_bound #define p push #define pb push_back #define fastio ios::sync_with_stdio(false);cin.tie(NULL); using namespace std; #define int long long const int mxn=5005,mod=69,lg=42,root=80,inf=1e18; vector<int>adj[mxn+10]; bitset<mxn+10>on; int n,ans=inf; void solve(int root){ on.reset(); queue<int>q; vector<int>val(n+1); int sum=1; val[root]=1; q.push(root); while(!q.empty()){ int cur=q.front(); q.pop(); on[cur]=true; for(auto i:adj[cur]){ if(on[i])continue; on[i]=true; val[i]=val[cur]+1; sum+=val[i]; q.push(i); } } for(int i=1;i<=n;i++)if(!on[i])return; ans=min(ans,sum); } int32_t main(){ fastio cin>>n; for(int i=1;i<=n;i++){ int a;cin>>a; for(int j=0;j<a;j++){ int v;cin>>v; adj[v].pb(i); } } for(int i=1;i<=n;i++)solve(i); cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...