제출 #595809

#제출 시각아이디문제언어결과실행 시간메모리
595809BelphegorBosses (BOI16_bosses)C++14
0 / 100
1 ms340 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; vector<int>tree[5005]; int depth[5005]; int f(int root){ memset(depth,0,sizeof(depth)); depth[root] = 1; queue<int>q; q.push(root); int ret = 0; while(!q.empty()){ int cur = q.front(); q.pop(); ret+=depth[cur]; for(int nxt:tree[cur]){ if(depth[nxt]) continue; depth[nxt] = depth[cur]+1; q.push(nxt); } } return ret; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin>>n; for(int i=1; i<=n; i++){ int k; cin>>k; for(int j=0; j<k; j++){ int x; cin>>x; tree[x].emplace_back(i); } } int ans = INT32_MAX; for(int i=1; i<=n; i++) ans = min(ans,f(i)); cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...