# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
368062 | benedict0724 | Bosses (BOI16_bosses) | C++17 | 1247 ms | 888 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;
vector<int> adj[5001];
queue<int> q;
bool visited[5001];
int dp[5001], parent[5001];
int n;
int bfs(int x){
for(int i=1;i<=n;i++){
visited[i] = false;
dp[i] = 0;
}
visited[x] = true;
vector<int> seq;
q.push(x);
while(!q.empty()){
int now = q.front(); q.pop();
for(int i : adj[now]){
if(!visited[i]){
visited[i] = true;
parent[i] = now;
q.push(i);
}
}
seq.push_back(now);
}
if(seq.size() != n) return 1e9;
int sum = 0;
for(int i=n-1;i>=0;i--){
dp[seq[i]] += 1;
dp[parent[seq[i]]] += dp[seq[i]];
sum += dp[seq[i]];
}
return sum;
}
int main()
{
ios::sync_with_stdio(false); cin.tie(NULL);
cin >> n;
for(int i=1;i<=n;i++){
int k; cin >> k;
for(int j=1;j<=k;j++){
int e; cin >> e;
adj[e].push_back(i);
}
}
int ans = 1e9;
for(int i=1;i<=n;i++){
ans = min(ans, bfs(i));
}
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... |