# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
791081 | AndiR | Bosses (BOI16_bosses) | C++14 | 964 ms | 652 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 <fstream>
#include <vector>
#include <queue>
using namespace std;
ifstream fin ("bos.in");
ofstream fout ("bos.out");
typedef long long ll;
const int Nmax=5000;
int n;
bool vis[Nmax];
vector <pair<int, bool>> ad[Nmax];
queue <int> q;
ll sol, mn=(ll)99999999999999999;
int dfs(int nod){
int s=1;
for (int i=0; i<ad[nod].size(); i++){
if (ad[nod][i].second==1){
ad[nod][i].second=0;
s+=dfs(ad[nod][i].first);
}
}
sol+=s;
return s;
}
int main()
{
cin>>n;
int m, a;
for (int i=0; i<n; i++){
cin>>m;
for (int j=0; j<m; j++){
cin>>a; a--;
ad[a].push_back({i, 0});
}
}
for (int i=0; i<n; i++){
sol=0;
vis[i]=1;
q.push(i);
while (!q.empty()){
for (int j=0; j<ad[q.front()].size(); j++){
if (vis[ad[q.front()][j].first]==0){
q.push(ad[q.front()][j].first);
vis[ad[q.front()][j].first]=1;
ad[q.front()][j].second=1;
}
}
q.pop();
}
bool ok=1;
for (int i=0; i<n; i++){
if (vis[i]==0)
ok=0;
vis[i]=0;
}
dfs(i);
if (sol<mn && ok)
mn=sol;
}
cout<<mn;
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... |