제출 #813332

#제출 시각아이디문제언어결과실행 시간메모리
813332akariBosses (BOI16_bosses)C++14
67 / 100
27 ms10376 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define fi first #define se second #define ii pair<ll,ll> const ll maxn=2e5+2; int n; vector<int> adj[maxn]; vector<int> g[4000]; int dp[4000]; int ans=INT_MAX; int sum,cnt; void dfs(int u){ //cout<<u<<endl; dp[u]=1; ++cnt; for (int v: g[u]){ dfs(v); dp[u]+=dp[v]; } sum+=dp[u]; } void bfs(int s){ bool ok[n+3]={}; queue<int> q; q.push(s); ok[s]=1; for (int i=1;i<=n;++i) g[i].clear(); while (!q.empty()){ int u=q.front(); q.pop(); for (int v: adj[u]){ if (!ok[v]){ ok[v]=1; q.push(v); g[u].push_back(v); } } } sum=cnt=0; /*for (int i=1;i<=n;++i){ for (int j: g[i]) cout<<j<<" "; cout<<endl; }*/ dfs(s); //cout<<endl; //cout<<s<<" "<<sum<<endl; if (cnt==n) ans=min(ans,sum); } int main(){ cin>>n; for (int i=1;i<=n;++i){ int k; cin>>k; while (k--){ int x; cin>>x; adj[x].push_back(i); //cout<<x<<" "<<i<<endl; } } //bfs(1); //cout<<endl; for (int i=1;i<=n;++i) bfs(i); cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...