Submission #1122985

#TimeUsernameProblemLanguageResultExecution timeMemory
1122985I_FloPPed21Bosses (BOI16_bosses)C++20
0 / 100
1 ms584 KiB
#include <iostream> #include <vector> #include <queue> using namespace std; const int N=5e3+2; int n; //observatie generala costul e size-ul subtreeului vector<int>prioritate[N]; vector<int>adj[N]; void citeste() { cin>>n; for(int i=1;i<=n;i++) { int size; cin>>size; for(int indice=1;indice<=size;indice++) { int sef; cin>>sef; prioritate[sef].push_back(i); } } } int dp[N]; int global=0; int ans=1e9; void dfs(int nod,int p) { dp[nod]=1; for(auto u:adj[nod]) { if(u!=p) { dfs(u,nod); dp[nod]+=dp[u]; } } global+=dp[nod]; } void parcurge(int sef) { queue<int>q; q.push(sef); vector<bool>viz(n+1,0); viz[sef]=true; for(int i=1;i<=n;i++) { adj[i].clear(); } while(!q.empty()) { int nod=q.front(); for(auto u:prioritate[nod]) { if(viz[u]==false) { adj[u].push_back(nod); adj[nod].push_back(u); viz[u]=true; q.push(u); } } q.pop(); } global=0; dfs(sef,0); ans=min(ans,global); } void rezolva() { for(int i=1;i<=n;i++) { parcurge(i); } cout<<ans<<'\n'; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); citeste(); rezolva(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...