Submission #1066395

#TimeUsernameProblemLanguageResultExecution timeMemory
1066395boris_7Bosses (BOI16_bosses)C++17
0 / 100
1 ms348 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; vector<vector<int>>gp; vector<int>vis; vector<int> sub; int ans = INT_MAX,cnt=0; void dfs(int u){ for(int &i:gp[u]){ if(!vis[i]){ vis[i]=1; dfs(i); sub[u]+=sub[i]; } } cnt+=sub[u]; if(vis[u]==2){ ans = min(ans,cnt); } } void solve(){ int n; cin>>n; gp = vector<vector<int>>(n); for(int i =0;i<n;i++){ int x; cin>>x; while(x--){ int v; cin>>v; gp[--v].push_back(i); } } for(int i = 0;i<n;i++){ vis = vector<int>(n); sub = vector<int>(n,1); vis[i]=2; cnt = 0; dfs(i); } cout<<ans<<endl; } signed main(){ ios_base::sync_with_stdio(0); cin.tie(nullptr); // ll t;cin>>t;while(t--) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...