#include<bits/stdc++.h>
#include <chrono>
#include <random>
using namespace std;
#define F first
#define S second
#define pb push_back
#define vll vector<ll>
#define pll pair<ll, ll>
typedef long long ll;
const ll mxN=5005;
const ll inf=1e18;
vll adj[mxN];
ll k[mxN];
vll boss[mxN];
bool visited[mxN];
void solve(){
ll n;
cin>>n;
for(ll i=1;i<=n;i++){
cin>>k[i];
for(ll j=0;j<k[i];j++){
ll tep;
cin>>tep;
boss[i].pb(tep);
adj[tep].pb(i);
}
}
ll ans=inf;
for(ll s=1;s<=n;s++){
memset(visited, 0, sizeof(visited));
queue<pll> q;
q.push({s, 1});
ll tans=0;
while(!q.empty()){
pll cur=q.front(); q.pop();
if(visited[cur.F]) continue;
visited[cur.F]=1;
tans+=cur.S;
for(auto &it:adj[cur.F]){
q.push({it, cur.S+1});
}
}
ans=min(ans, tans);
}
cout<<ans<<'\n';
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |