Submission #858316

#TimeUsernameProblemLanguageResultExecution timeMemory
8583168pete8Bosses (BOI16_bosses)C++14
0 / 100
1 ms604 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; int solve(int root){ on.reset(); queue<int>q; vector<int>go[mxn+10],val(n+1); q.push(root); vector<pii>d(n); for(int i=0;i<n;i++)d[i].s=i+1; while(!q.empty()){ int cur=q.front(); q.pop(); on[cur]=true; for(auto i:adj[cur]){ if(on[i])continue; d[i-1].f=d[cur-1].f+1; q.push(i); go[cur].pb(i); } } sort(rall(d)); for(int i=0;i<n;i++){ for(auto j:go[d[i].s])val[d[i].s]+=val[j]; val[d[i].s]++; } for(int i=1;i<=n;i++)if(!on[i])return inf; int sum=0; for(int i=1;i<=n;i++)sum+=val[i]; return 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); } } int ans=inf; for(int i=1;i<=n;i++)ans=min(ans,solve(i)); cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...