# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
973892 | KasymK | Bosses (BOI16_bosses) | C++17 | 860 ms | 1264 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;
int n;
const int N = 5e3 + 5;
vector<int> adj[N];
vector<int> taze_adj[N];
int vis[N], node_sany[N];
void dfs(int x){
node_sany[x] = 1;
for(auto to : taze_adj[x]){
dfs(to);
node_sany[x] += node_sany[to];
}
}
int kok(int x){
for(int i = 1; i <= n; ++i){
vis[i] = 0;
node_sany[i] = 0;
taze_adj[i].clear();
}
queue<int> q;
q.push(x);
vis[x] = 1;
while(!q.empty()){
int id = q.front();
q.pop();
for(auto to : adj[id])
if(!vis[to]){
vis[to] = 1;
taze_adj[id].push_back(to);
q.push(to);
}
}
for(int i = 1; i <= n; ++i)
if(!vis[i])
return -1;
// eger birini hem gormedik bolsam, onda yalnysh bolyar
dfs(x);
int ret = 0;
for(int i = 1; i <= n; ++i)
ret += node_sany[i];
return ret;
}
int main(){
scanf("%d", &n);
for(int i = 1; i <= n; ++i){
int K;
scanf("%d", &K);
while(K--){
int A;
scanf("%d", &A);
adj[A].push_back(i);
}
}
int ans = INT_MAX;
for(int i = 1; i <= n; ++i){
int kk = kok(i);
if(~kk)
ans = min(ans, kk);
}
printf("%d\n", ans);
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... |