# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
695158 | Mr_Ph | Bosses (BOI16_bosses) | C++14 | 2 ms | 340 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.
///Never gonna give you up.
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
typedef long long ll;
typedef long long int lli;
typedef unsigned long long ull;
using namespace std;
using namespace __gnu_pbds;
template<class x>
using ordered_set = tree<x, null_type,less<x>, rb_tree_tag,tree_order_statistics_node_update>;
const ll mod=(ll)1e9+7;
const ll mod1=998244353;
///the defines :)
#define endl '\n'
#define vi vector<int>
#define vll vector<ll>
#define ent(arr) for(int i=0;i<arr.size();i++)cin>>arr[i];
#define all(arr) arr.begin(),arr.end()
#define allr(arr) arr.rbegin(),arr.rend()
#define sz size()
#define int long long
///the end of the defines ;)
void bla()
{
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("notsus.txt","w",stdout);
#endif
}
int n;
vector<vector<int>>padj;
vector<vector<int>>adj;
vector<bool>vs;
map<int,int>val;
vector<bool>vs1;
map<int,int>val1;
vector<vector<int>>build(int node)
{
vector<vector<int>>yay(n+1);
map<int,int>mp;
queue<int>q;
q.push(node);
map<int,int>mp1;
while(q.sz)
{
mp1[q.front()]++;
mp[q.front()]++;
for(auto i:padj[q.front()])
{
if(!mp1[i])
{
yay[q.front()].push_back(i);
mp[i]++;
q.push(i);
mp1[i]++;
}
}
q.pop();
}
return yay;
}
int hello=0;
void dfs(int node)
{
vs[node]=true;
val[node]=1;
for(auto i:adj[node])
{
if(!vs[i])dfs(i);
val[node]+=val[i];
}
}
void preprocess(){}
void solve()
{
cin>>n;
padj.resize(n+1);
vs.resize(n+1);
vs1.resize(n+1);
adj.resize(n+1);
for(int i=0;i<n;i++)
{
int x;
cin>>x;
for(int j=0;j<x;j++)
{
int a;
cin>>a;
padj[a].push_back(i+1);
}
}
int ans=1e18;
for(int i=1;i<=n;i++)
{
vs=vs1;
val=val1;
adj=build(i);
hello=0;
dfs(i);
for(auto i:val)
{
hello+=i.second;
}
ans=min(ans,hello);
}
cout<<ans<<endl;
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
preprocess();
bla();
int t=1;
//cin>>t;
while(t--)
solve();
}
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... |