# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
208084 | kai824 | Bosses (BOI16_bosses) | C++17 | 7 ms | 3832 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;
#define int long long
bool vis[5005];
int n,k,a,ans=INT_MAX;
int preorder[5005],nex;
int cur,nodes;
vector<int> children[5005];
stack<int> children2[5005];
void dfs(int x){//returns salary of employee x...
preorder[x]=nex++;
while(!children2[x].empty()){
a=children2[x].top();
children2[x].pop();
dfs(a);
}
cur+=nex-preorder[x];
}
int32_t main() {
ios_base::sync_with_stdio(false);cin.tie(0);
queue<int> bfs;
cin>>n;
for(int x=1;x<=n;x++){
cin>>k;
while(k--){
cin>>a;
children[a].push_back(x);
}
}
for(int x=1;x<=n;x++){
for(int i=1;i<=n;i++)vis[i]=0;
bfs.push(x);vis[x]=1;
nodes=0;
while(!bfs.empty()){
nodes++;
a=bfs.front();
bfs.pop();
for(int i=0;i<children[a].size();i++){
if(!vis[children[a][i]]){
vis[children[a][i]]=true;
bfs.emplace(children[a][i]);
children2[a].push(children[a][i]);
}
}
}
if(nodes!=n)continue;
cur=0;
nex=1;
dfs(x);
ans=min(ans,cur);
}
cout<<ans<<'\n';
return 0;
}
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... |