# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
851135 | Benmath | Bosses (BOI16_bosses) | C++14 | 28 ms | 860 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.
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> v[5010];
int vis[5010];
int vis_dfs[5010];
int subtree[5010];
vector<int> adjl[5010];
int brojac = 0;
int brojac_posj = 0;
void dfs (int s){
vis_dfs[s]++;
subtree[s]++;
for(int i = 0; i < adjl[s].size(); i++){
if(vis_dfs[adjl[s][i]] == 0){
dfs(adjl[s][i]);
subtree[s] += subtree[adjl[s][i]];
}
}
brojac = brojac + subtree[s];
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for (int i = 1; i <= n; i++){
int x;
cin >> x;
for(int j = 0;j < x;j++){
int y;
cin >> y;
v[i].push_back(y);
}
}
int ans = 1e9;
for(int i = 1; i <= n; i++){
brojac_posj = 0;
for(int j = 1; j <= n; j++){
vis[j] = 0;
vis_dfs[j] = 0;
subtree[j] = 0;
adjl[j].clear();
}
vis[i]++;
brojac_posj++;
brojac = 0;
queue<int>q;
q.push(i);
if(n<=4000){
while (!q.empty()){
int a = q.front();
q.pop();
for (int j = 1; j <= n; j++){
if (vis[j] == 0){
for (int k = 0; k < v[j].size(); k++){
if(v[j][k] == a){
adjl[a].push_back(j);
vis[j]++;
brojac_posj++;
q.push(j);
break;
}
}
}
}
}
if(brojac_posj == n){
dfs (i);
ans = min(ans, brojac);
}
}
}
cout << ans;
}
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... |