Submission #813721

#TimeUsernameProblemLanguageResultExecution timeMemory
813721dijbkrBosses (BOI16_bosses)C++14
0 / 100
16 ms24788 KiB
#include<bits/stdc++.h> typedef long long ll; typedef unsigned long long ull; using namespace std; const ll maxn=500005; ll n; vector<ll>adj[maxn]; vector<ll>adj_1[maxn]; ll dp[maxn]; bool used[maxn]; bool used_1[maxn]; ll DFS(ll u) { used[u]=true; for (auto it:adj_1[u]) { if (used[it]==false) { DFS(it); dp[u]+=dp[it]; } } return dp[u]; } ll BFS(ll u) { memset(used,false,sizeof(used)); memset(used_1,false,sizeof(used_1)); queue<ll>q; q.push(u); used_1[u]=true; for (ll i=1; i<=n; i++) { adj_1[i].clear(); } while (!q.empty()) { ll v=q.front(); q.pop(); for (auto it:adj[v]) { if (used_1[it]==false) { used_1[it]=true; adj_1[v].push_back(it); q.push(it); } } } ll res=0; DFS(u); for (ll i=1; i<=n; i++) { res+=dp[i]; } return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n; for (ll i=1; i<=n; i++) { ll t; cin >> t; while (t--) { ll x; cin >> x; adj[x].push_back(i); } } for (ll i=1; i<=n; i++) { dp[i]=1; } // adj_1[1].push_back(2); // adj_1[1].push_back(3); // adj_1[3].push_back(4); // cout << DFS(1); // cout << endl << dp[4]; // cout << BFS(1) << endl; // cout << dp[1]+dp[2]+dp[3]+dp[4] << endl; ll ans=1e18; for (ll j=1; j<=n; j++) { for (ll i=1; i<=n; i++) { dp[i]=1; } //cout << j << " " << BFS(j) << endl; ans=min(ans,BFS(j)); } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...