Submission #350741

#TimeUsernameProblemLanguageResultExecution timeMemory
350741MHNaderiBosses (BOI16_bosses)C++14
0 / 100
1 ms620 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> #define all(x) x.begin() , x.end() #define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout); #define random_init mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); #define int long long #define pb push_back #define pii pair<int,int> #define F first #define S second const int maxn=1e4,INF=1e18; int dis[maxn],mark[maxn],cntd[maxn]; vector<int> m[maxn]; inline int BFS(int u,int n){ queue<int> q; q.push(u); mark[u]=1; dis[u]=1; cntd[1]=1; int mx=0; // cout<<"####"<<u<<"####"<<'\n'; while(q.size()){ u=q.front(); for(int v : m[u]){ if(!mark[v]){ dis[v]=dis[u]+1; cntd[dis[v]]++; mark[v]=1; q.push(v); } } mx=dis[u]; q.pop(); } int ans=0,sum=0; for(int i=mx;i>0;i--){ sum+=cntd[i]; ans+=sum; // cout<<i<<" "<<cntd[i]<<'\n'; } for(int i=0;i<=n;i++){ dis[i]=cntd[i]=mark[i]=0; } return ans; } int32_t main(){ ios_base::sync_with_stdio(0); int n; cin>>n; for(int i=1;i<=n;i++){ int k; cin>>k; for(int j=0;j<k;j++){ int x; cin>>x; m[x].pb(i); } } int ans=INF; for(int i=1;i<=n;i++){ ans=min(ans,BFS(i,n)); } cout<<ans<<'\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...