# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
533491 | makanhulia | Bosses (BOI16_bosses) | C++17 | 1 ms | 460 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>
#define ll long long
#define fi first
#define se second
const ll MOD=1e9+7;
using namespace std;
ll N,M,memo[5005];
bool visited[5005];
vector <ll> adj[5005];
ll dp(ll x){
if(memo[x]!=-1){
return memo[x];
}
vector <ll> vec;
for(int i=0;i<adj[x].size();i++){
if(!visited[adj[x][i]]){
vec.push_back(adj[x][i]);
visited[adj[x][i]]=true;
}
}
ll ret=1;
for(int i=0;i<vec.size();i++){
ret+=dp(vec[i]);
}
return memo[x]=ret;
}
int main(){
cin>>N;
for(int i=1;i<=N;i++){
cin>>M;
for(int j=1;j<=M;j++){
ll temp;
cin>>temp;
adj[temp].push_back(i);
}
}
ll minn=1e18;
for(int i=1;i<=N;i++){
memset(visited,false,sizeof(visited));
memset(memo,-1,sizeof(memo));
visited[i]=true;
ll temp=dp(i);
ll sum=0;
for(int j=1;j<=N;j++){
sum+=memo[j];
}
minn=min(minn,sum);
}
cout<<minn<<endl;
}
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... |