# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
950305 | LittleOrange | Bosses (BOI16_bosses) | C++17 | 598 ms | 1484 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll big = 1e18;
int main(){
ios::sync_with_stdio(0);cin.tie(0);
ll n;
cin >> n;
vector<vector<ll>> ch(n);
for(ll i = 0;i<n;i++){
ll k;
cin >> k;
while(k--){
ll p;
cin >> p;
ch[p-1].push_back(i);
}
}
ll ans = big;
for(ll rt = 0;rt<n;rt++){
//cout << "Try " << rt+1 << "\n";
vector<ll> u(n,0),p(n,rt);
deque<ll> q;
q.push_back(rt);
u[rt] = 1;
vector<ll> v;
while(!q.empty()){
v.push_back(q.front());
ll i = q.front();q.pop_front();
for(ll j : ch[i]) if(!u[j]){
//cout << i+1 << "->" << j+1 << "\n";
u[j] = 1;
p[j] = i;
q.push_back(j);
}
}
if(v.size()<n) continue;
reverse(v.begin(),v.end());
vector<ll> h(n,1);
for(ll i : v){
if(p[i]!=i) h[p[i]] += h[i];
}
//for(ll i = 0;i<n;i++) cout << p[i] << " \n"[i+1==n];
//for(ll i = 0;i<n;i++) cout << h[i] << " \n"[i+1==n];
ll cur = 0;
for(ll i : h) cur += i;
ans = min(ans,cur);
}
cout << ans << "\n";
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |