제출 #767601

#제출 시각아이디문제언어결과실행 시간메모리
7676011neBosses (BOI16_bosses)C++14
67 / 100
1577 ms852 KiB
/* * author : Apiram * created: 27.06.2023 03:25:28 */ #include<bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); int n;cin>>n; vector<vector<int>>adj(n); for (int i = 0;i<n;++i){ int k;cin>>k; for (int j = 0;j<k;++j){ int x;cin>>x; --x; adj[x].push_back(i); } } int pos = 1e9; for (int i = 0;i<n;++i){ priority_queue<pair<int,int>>q; int curv = 1; int ans = 0; vector<int>visited(n,false); vector<int>parent(n,-1); vector<int>depth(n,0); visited[i] = true; vector<vector<int>>nx(n); q.push({0,i}); vector<int>cost(n,1); while(!q.empty()){ auto u = q.top(); q.pop(); for (auto x:adj[u.second]){ if (!visited[x]){ visited[x] = true; parent[x] = u.second; depth[x] = depth[u.second] + 1; nx[u.second].push_back(x); q.push({-(-u.first + 1),x}); curv++; } } } if (curv == n){ vector<int>order(n); iota(order.begin(),order.end(),0); sort(order.begin(),order.end(),[&](int x,int y){ return depth[x] > depth[y]; }); for (auto j:order){ for (auto y:nx[j]){ cost[j]+=cost[y]; } } for (int j = 0;j<n;++j){ // cout<<cost[j]<<" "; ans+=cost[j]; } //cout<<'\n'; pos = min(pos,ans); } } cout<<pos<<'\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...