이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
#define ll long long
#define pb push_back
#define fr first
#define sc second
#define MAX ((ll)(1e9+100))
#define MX ((ll)(1e6+100))
#define ARRS ((ll)(2e6+100))
#define HS ((ll)(233))
#define MOD ((ll)(1e9+7))
#define EP ((double)(1e-9))
#define LG 21
#define mul(a,b) a=((a)*(b))%MOD
using namespace std;
ll n;
ll m,k;
vector<ll> v[ARRS];
ll f[ARRS];
int main(){
#ifdef KHOKHO
freopen("in.in","r",stdin);
freopen("out.out","w",stdout);
#endif // KHOKHO
ios::sync_with_stdio(0);
cin>>n;
for(int i=1; i<=n; i++){
cin>>m;
while(m--){
cin>>k;
v[k].pb(i);
}
}
ll pas=MAX;
for(int i=1; i<=n; i++){
for(int i=1; i<=n; i++)f[i]=0;
queue<pair<ll,ll> > q;
q.push({i,1});
ll p=0;
while(q.size()){
auto x=q.front();
q.pop();
if(f[x.fr])continue;
f[x.fr]=1;
p+=x.sc;
for(auto y:v[x.fr])
q.push({y,x.sc+1});
}
bool e=1;
for(int i=1; i<=n; i++)e&=f[i];
if(e)
pas=min(pas,p);
}
cout<<pas;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |