# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1066415 |
2024-08-19T20:58:05 Z |
boris_7 |
Bosses (BOI16_bosses) |
C++17 |
|
533 ms |
860 KB |
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
vector<vector<ll>>gp;
vector<ll>vis;
vector<ll> d;
ll n;
ll ans = LLONG_MAX;
void bfs(ll u){
queue<ll>q;
q.push(u);
vis[u]=1;
d[u]=1;
ll cnt = 0,comp=0;
while(q.size()){
ll v = q.front();
q.pop();
comp++;
cnt+=d[v];
for(ll &i:gp[v]){
if(!vis[i]){
vis[i]=1;
d[i]=d[v]+1;
q.push(i);
}
}
}
if(comp==n){
ans = min(ans,cnt);
}
}
void solve(){
cin>>n;
gp = vector<vector<ll>>(n);
for(ll i =0;i<n;i++){
ll x;
cin>>x;
while(x--){
ll v;
cin>>v;
gp[--v].push_back(i);
}
}
for(ll i = 0;i<n;i++){
vis = vector<ll>(n);
d = vector<ll>(n);
bfs(i);
}
cout<<ans<<endl;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
// ll t;cin>>t;while(t--)
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
456 KB |
Output is correct |
12 |
Correct |
4 ms |
604 KB |
Output is correct |
13 |
Correct |
4 ms |
604 KB |
Output is correct |
14 |
Correct |
98 ms |
604 KB |
Output is correct |
15 |
Correct |
7 ms |
860 KB |
Output is correct |
16 |
Correct |
465 ms |
860 KB |
Output is correct |
17 |
Correct |
524 ms |
860 KB |
Output is correct |
18 |
Correct |
533 ms |
860 KB |
Output is correct |