#include<bits/stdc++.h>
#define endl "\n"
#define all(v) v.begin(),v.end()
#define st first
#define nd second
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long lo;
const int mod=1000000007,N=500005;
lo a,b,c,d,e,f,g=1,h[N],arr[N];
string s;
vector<lo>v[N];
lo bfs(lo x){
for(lo i=1;i<=a;i++)h[i]=0;
queue<pair<lo,lo> >q;
q.push({x,1});
while(q.size()){
lo node=q.front().st,hehe=q.front().nd;
q.pop();
if(h[node]) continue;
h[node]=hehe;
for(lo i=0;i<v[node].size();i++){
if(h[v[node][i]]==0)q.push({v[node][i],hehe+1});
}
}
lo sum=0;
for(lo i=1;i<=a;i++){
if(h[i]==0) return 1e18;
sum+=h[i];
}
return sum;
}
void solve(){
cin >> a;
for(lo i=1;i<=a;i++){
lo x,y;
cin >> x;
for(lo j=1;j<=x;j++){
cin >> y;
v[y].pb(i);
}
}
lo mn=1e18;
for(lo i=1;i<=a;i++){
mn=min(mn,bfs(i));
}
assert(mn!=1e18);
cout << mn << endl;
}
int main(){
#ifdef local
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
// cin >> g;
while(g--)solve();
}
Compilation message
bosses.cpp: In function 'lo bfs(lo)':
bosses.cpp:24:15: warning: comparison of integer expressions of different signedness: 'lo' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | for(lo i=0;i<v[node].size();i++){
| ~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
12032 KB |
Output is correct |
2 |
Correct |
10 ms |
12032 KB |
Output is correct |
3 |
Correct |
9 ms |
12108 KB |
Output is correct |
4 |
Correct |
9 ms |
12032 KB |
Output is correct |
5 |
Correct |
9 ms |
12032 KB |
Output is correct |
6 |
Correct |
9 ms |
12032 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
12032 KB |
Output is correct |
2 |
Correct |
10 ms |
12032 KB |
Output is correct |
3 |
Correct |
9 ms |
12108 KB |
Output is correct |
4 |
Correct |
9 ms |
12032 KB |
Output is correct |
5 |
Correct |
9 ms |
12032 KB |
Output is correct |
6 |
Correct |
9 ms |
12032 KB |
Output is correct |
7 |
Correct |
10 ms |
12032 KB |
Output is correct |
8 |
Correct |
9 ms |
12032 KB |
Output is correct |
9 |
Correct |
9 ms |
12160 KB |
Output is correct |
10 |
Correct |
9 ms |
12032 KB |
Output is correct |
11 |
Correct |
10 ms |
12032 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
12032 KB |
Output is correct |
2 |
Correct |
10 ms |
12032 KB |
Output is correct |
3 |
Correct |
9 ms |
12108 KB |
Output is correct |
4 |
Correct |
9 ms |
12032 KB |
Output is correct |
5 |
Correct |
9 ms |
12032 KB |
Output is correct |
6 |
Correct |
9 ms |
12032 KB |
Output is correct |
7 |
Correct |
10 ms |
12032 KB |
Output is correct |
8 |
Correct |
9 ms |
12032 KB |
Output is correct |
9 |
Correct |
9 ms |
12160 KB |
Output is correct |
10 |
Correct |
9 ms |
12032 KB |
Output is correct |
11 |
Correct |
10 ms |
12032 KB |
Output is correct |
12 |
Correct |
34 ms |
12288 KB |
Output is correct |
13 |
Correct |
32 ms |
12320 KB |
Output is correct |
14 |
Correct |
253 ms |
12312 KB |
Output is correct |
15 |
Correct |
29 ms |
12288 KB |
Output is correct |
16 |
Correct |
896 ms |
12536 KB |
Output is correct |
17 |
Correct |
1211 ms |
12448 KB |
Output is correct |
18 |
Correct |
1278 ms |
12416 KB |
Output is correct |