Submission #880422

#TimeUsernameProblemLanguageResultExecution timeMemory
880422JakobZorzBosses (BOI16_bosses)C++14
0 / 100
0 ms348 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]; bool vis[5000]; int pay[5000]; int dfs(int node){ vis[node]=true; int res=1; for(int ch:children[node]){ if(!vis[ch]){ res+=dfs(ch); } } pay[node]=res; return res; } int get(int root){ for(int i=0;i<n;i++) vis[i]=false; dfs(root); for(int i=0;i<n;i++) if(!vis[i]) return 1e9; 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...