이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define all(a) (a).begin(), (a).end()
//#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz() size()
#define fr first
#define sc second
#define pb push_back
#define er erase
#define in insert
#define pi pair<int,int>
#define pii pair<pair<int,int>,int>
#define mp make_pair
//#define int long long
#define rc(s) return cout<<s,0
#define rcc(s) cout<<s,exit(0)
//#define cin fin
//#define cout fout
using namespace std;
//ifstream fin("file.in");
//ofstream fout("file.out");
const int nmax=1e3+5;
const int mod=1e9+7;
const int mod1=998244353;
int n,t,x,ans=1e9,dp[5005];
bitset<5005>viz;
vector<int>cop[5005],nod[5005];
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n;
for(int i=1;i<=n;i++){
cin >> t;
for(int j=1;j<=t;j++){
cin >> x;
cop[x].push_back(i);
}
}
for(int i=1;i<=n;i++){
viz.reset();
queue<int>q;
q.push(i);
viz[i]=1;
dp[i]=1;
int cnt=1;
while(!q.empty()){
x=q.front();
for(auto it:cop[x]){
if(!viz[it]){
cnt++;
viz[it]=1;
q.push(it);
dp[it]=dp[x]+1;
}
}
q.pop();
}
if(cnt!=n) continue;
int rs=0;
for(int j=1;j<=n;j++){
rs+=dp[j];
}
ans=min(ans,rs);
}
rc(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... |