이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define fi first
#define se second
#define pitem item*
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
const int N=1e5+10;
const int SS=1<<19;
const int INFi=2e9;
const ll INFl=1e13;
const ll mod2=998244353;
const ll mod=1e9+7;
const ll mod3=1000696969;
const ll p=70032301;
const ull p2=913;
const int L=20;
int odl[N],n;
vi graf[N];
int bfs(int v){
deque<int>deq;
deq.push_back(v);
for(int i=1;i<=n;i++) odl[i]=0;
odl[v]=1;
int res=0;
while(deq.size()){
int u=deq.front();
deq.pop_front();
res+=odl[u];
for(auto curr:graf[u])
if(odl[curr]==0) odl[curr]=odl[u]+1,deq.push_back(curr);
}
for(int i=1;i<=n;i++) if(odl[i]==0) res=INFi;
return res;
}
void solve(){
cin>>n;
for(int a,i=1;i<=n;i++){
cin>>a;
while(a--){
int b;
cin>>b;
graf[b].push_back(i);
}
}
int res=INFi;
for(int i=1;i<=n;i++) res=min(res,bfs(i));
cout<<res<<"\n";
}
int main(){
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |