# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
735642 | MODDI | Bosses (BOI16_bosses) | C++14 | 634 ms | 764 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>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<long long, long long> pll;
typedef pair<int,int> pii;
typedef vector<long long> vl;
typedef vector<int> vi;
int n;
vi G[5100];
vector<pii> ord;
ll rez = 0, all = 0;
bool vis[5100];
void bfs(int v, int br)
{
if(vis[v] and br!=ord.size()){bfs(ord[br].first, br+1); return;}
else if(vis[v] and br==ord.size())return;
vis[v]=true;
all++;
if(br==0)rez+=1;
else rez+=ord[br-1].second;
for(auto next : G[v])
{
if(!vis[next] and br!=0){ord.push_back({next, ord[br-1].second+1});}
else if (!vis[next] and br==0)ord.push_back({next, 2});
}
if(br==ord.size())return;
bfs(ord[br].first, br+1);
}
int main(){
cin>>n;
for(int i = 0; i < n; i++){
int k;
cin>>k;
for(int j = 0; j < k; j++){
int a;
cin>>a;
a--;
G[a].pb(i);
}
}
ll ans = 1e9;
for(int i = 0; i < n; i++){
rez = 0;
all = 0;
memset(vis, false, sizeof vis);
ord.clear();
bfs(i, 0);
// cout<<rez<<endl;
if(all==n) ans = min(ans, rez);
}
cout<<ans<<endl;
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... |