# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
30905 | Navick | Bosses (BOI16_bosses) | C++14 | 533 ms | 2312 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>
#define F first
#define S second
#define pb push_back
using namespace std;
typedef long long ll;
typedef long double ld;
const int N = 5100, INF = 1e9;
int dis[N], que[N], st, en, n;
vector<int> adj[N];
inline int solve(int s){
st = en = 0;
que[en++] = s;
for(int i=1; i<=n; i++)
dis[i] = INF;
dis[s] = 0;
while(en - st){
int v = que[st++];
for(auto u : adj[v])
if(dis[u] == INF){
dis[u] = dis[v] + 1;
que[en++] = u;
}
}
int res = n;
for(int i=1; i<=n; i++){
if(dis[i] == INF)return INF;
else res += dis[i];
}
return res;
}
int main(){
scanf("%d", &n);
for(int i=1; i<=n; i++){
int k; scanf("%d", &k);
while(k--){
int v; scanf("%d", &v);
adj[v].pb(i);
}
}
int ans = INF;
for(int i=1; i<=n; i++){
ans = min(ans, solve(i));
}
printf("%d\n", 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... |