# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
98958 | zicon35 | Bosses (BOI16_bosses) | C++14 | 2 ms | 384 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;
int n,k,v;
vector< vector<int>> adj;
int ans=1e9;
map<int,int> vis;
set<int> seen;
void dfs(int u,int d,int & sum,int n){
if(vis[u]){
return;
}
//cout<<"u: "<<u<<d<<sum<<endl;
vis[u] = 1;
seen.insert(u);
for(int i=0;i<adj[u].size();i++){
int to = adj[u][i];
if(!vis[to]){
sum += d;
//cout<<"test"<<endl;
dfs(to,d+1,sum,n);
}
}
if(seen.size()==n){
//cout<<"here"<<sum+d<<endl;
ans = min(ans,sum+d);
seen.clear();
return;
}
}
long long solve(int n){
cin>>n;
adj.resize(n+2);
for(int i=1;i<=n;i++){
cin>>k;
for(int j=1;j<=k;j++){
cin>>v;
adj[v].push_back(i);
}
}
for(int i=1;i<=n;i++){
int sum = 1;
vis.clear();
seen.clear();
dfs(i,1,sum,n);
}
return ans;
}
int main(){
cout<<solve(n)<<endl;
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... |