이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<limits.h>
#include<cmath>
#include<set>
#include<algorithm>
#include<bitset>
#include<list>
using namespace std;
#define ll long long
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#define ppii pair<int,pii>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define p push
#define pb push_back
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
#define int long long
const int mxn=5005,mod=69,lg=42,root=80,inf=1e18;
vector<int>adj[mxn+10];
bitset<mxn+10>on;
int n,ans=inf;
void solve(int root){
on.reset();
queue<int>q;
vector<int>val(n+1);
int sum=1;
val[root]=1;
q.push(root);
while(!q.empty()){
int cur=q.front();
q.pop();
on[cur]=true;
for(auto i:adj[cur]){
if(on[i])continue;
on[i]=true;
val[i]=val[cur]+1;
sum+=val[i];
q.push(i);
}
}
for(int i=1;i<=n;i++)if(!on[i])return;
ans=min(ans,sum);
}
int32_t main(){
fastio
cin>>n;
for(int i=1;i<=n;i++){
int a;cin>>a;
for(int j=0;j<a;j++){
int v;cin>>v;
adj[v].pb(i);
}
}
for(int i=1;i<=n;i++)solve(i);
cout<<ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |