# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
292087 | Abdelrahman | Bosses (BOI16_bosses) | C++17 | 1 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>
#define endl '\n'
#define modulo 1000000007
#define int long long
#pragma GCC optimize("-Ofast")
#define float double
#define PI 3.141592653589793238462643383279502884
#define sinDegrees(x) sin((x) * PI / 180.0)
#define tanDegrees(x) tan((x) * PI / 180.0)
#define atanDegrees(x) atan(x)* 180.0 / PI
using namespace std;
unordered_map<int, vector<int> > mp;
bool visited[5001] = {0}, touched[5001]={0};
int finale = 0, done=0;
bool compare(pair<int, int> a, pair<int, int> b)
{
if (a.first!=b.first)
{
return a.first>b.first;
}
else
{
return a.second<b.second;
}
}
int solve(int emp)
{
if (visited[emp])
return 0;
//cout<<emp<<" ";
visited[emp] = 1;
done++;
touched[emp] = 1;
int current = 0;
vector<int> myEmp;
for (int i=0;i<mp[emp].size();i++)
{
int mpNum=mp[emp][i];
if (touched[mpNum])
{
continue;
}
touched[mpNum] = 1;
myEmp.push_back(mpNum);
}
if (myEmp.size()==0)
{
finale+=1;
//cout<<1<<endl;
return 1;
}
for (int i=0;i<myEmp.size();i++)
{
current+=solve(myEmp[i]);
}
finale+=current+1;
//cout<<current+1<<endl;
return current+1;
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin>>n;
for (int i=0;i<n;i++)
{
int a;
cin>>a;
while (a--)
{
int b;
cin>>b;
mp[b-1].push_back(i);
}
}
int mini=INT_MAX;
for (int i=0;i<n;i++)
{
//cout<<"NEW"<<endl;
solve(i);
if (done==n)
{
//cout<<finale<<endl;
mini = min(finale, mini);
}
for (int j=0;j<n;j++)
{
visited[j]=0;
touched[j]=0;
}
finale = 0;
done=0;
}
cout<<mini;
}
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... |