제출 #458053

#제출 시각아이디문제언어결과실행 시간메모리
458053ZaZo_Bosses (BOI16_bosses)C++14
100 / 100
826 ms680 KiB
//Sorry but iam targeting IOI :)) //NEVER LOSE HOPE #pragma GCC optimize ("O3") #pragma GCC optimize ("unroll-loops") #include <bits/stdc++.h> #define endl "\n" #define ceil(a,b) (a+(b-1))/b #define all(v) v.begin(),v.end() #define int long long int #define Hidden ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0); using namespace std; const int N=3e4+10,mod = 1e9+7; vector<int>edges[5001]; int mn=INT_MAX,val=0,n,ans=INT_MAX; void bfs(int node) { queue<pair<int,int>>q; q.push({node,1}); int vis[5001]={0}; vis[node]=1; int c=1; val=1; while(!q.empty()) { int x=q.front().first , y=q.front().second; q.pop(); for(auto i : edges[x]) { if(!vis[i]) vis[i]=1,q.push({i,y+1}),c++,val+=y+1; } //cout<<endl; if(c==n) break; } if(c==n) mn=min(mn,val); } int32_t main(){ cin>>n; for(int i = 1 ; i <= n ; i ++) { int k; cin>>k; while(k--) { int x; cin>>x; edges[x].push_back(i); // edges[x].push_back(i); } } for(int i = 1 ; i <= n ; i++) { bfs(i); ans=min(mn,ans); mn=INT_MAX; } cout<<ans<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...