Submission #880443

#TimeUsernameProblemLanguageResultExecution timeMemory
880443JakobZorzBosses (BOI16_bosses)C++14
67 / 100
1571 ms1236 KiB
#include<iostream> #include<vector> #include<queue> #include<stack> #include<algorithm> #include<limits.h> #include<math.h> #include<map> #include<set> #include<unordered_map> #include<unordered_set> #include<iomanip> #include<cstring> typedef long long ll; typedef unsigned long long ull; typedef long double ld; using namespace std; //const int MOD=1e9+7; //typedef pair<ll,ll>Point; //typedef pair<ll,ll>Line; //#define x first //#define y second int n; vector<int>children[5000]; vector<vector<int>>childs; vector<int>pay; void dfs(int node){ pay[node]=1; for(int ch:childs[node]){ dfs(ch); pay[node]+=pay[ch]; } } int get(int root){ vector<bool>vis(n); childs=vector<vector<int>>(n,vector<int>()); pay=vector<int>(n); unordered_set<int>level1,level2; level1.insert(root); vis[root]=true; while(!level1.empty()){ for(int i:level1){ for(int j:children[i]){ if(level2.find(j)==level2.end()&&!vis[j]){ level2.insert(j); vis[j]=true; childs[i].push_back(j); } } } level1=level2; level2.clear(); } for(int i=0;i<n;i++) if(!vis[i]) return 1e9; dfs(root); int res=0; for(int i=0;i<n;i++) res+=pay[i]; return res; } void solve(){ cin>>n; for(int i=0;i<n;i++){ int k; cin>>k; while(k--){ int c; cin>>c; children[c-1].push_back(i); } } int res=1e9; for(int i=0;i<n;i++){ res=min(res,get(i)); } cout<<res<<"\n"; } int main(){ ios::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL); //freopen("bank.in","r",stdin);freopen("bank.out","w",stdout); int t=1;//cin>>t; while(t--)solve(); return 0; } /* 4 1 4 3 1 3 4 2 1 2 1 3 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...