# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
533844 | groshi | Bosses (BOI16_bosses) | C++17 | 776 ms | 716 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<iostream>
#include<vector>
#include<queue>
#include<utility>
using namespace std;
struct wi{
vector<int> Q;
int odw=0;
}*w;
long long wynik=1e18;
int kiedy=0;
int ile=0;
long long mam=0;
void bfs(int x)
{
queue<pair<int,long long> > kolejka;
w[x].odw=x;
kolejka.push({x,1});
while(!kolejka.empty())
{
pair<int,long long> para=kolejka.front();
kolejka.pop();
ile++;
mam+=para.second;
for(int i=0;i<w[para.first].Q.size();i++)
{
int pom=w[para.first].Q[i];
if(w[pom].odw==x)
continue;
w[pom].odw=x;
kolejka.push({pom,para.second+1});
}
}
}
int main()
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
int n,s,x;
cin>>n;
w=new wi[n+3];
for(int i=1;i<=n;i++)
{
cin>>s;
for(int j=0;j<s;j++)
{
cin>>x;
w[x].Q.push_back(i);
}
}
for(int i=1;i<=n;i++)
{
kiedy=i;
ile=0;
mam=0;
bfs(i);
if(ile!=n)
continue;
wynik=min(wynik,mam);
}
cout<<wynik;
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... |