이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/**Lucky Boy**/
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for (int i = (a); i >= (b); --i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define maxc 1000000007
#define maxn 5005
#define maxm 500005
#define pii pair <int,int>
#define Task "Bosses"
template <typename T> inline void read(T &x){char c;bool nega=0;while((!isdigit(c=getchar()))&&(c!='-'));if(c=='-'){nega=1;c=getchar();}x=c-48;while(isdigit(c=getchar())) x=x*10+c-48;if(nega) x=-x;}
template <typename T> inline void writep(T x){if(x>9) writep(x/10);putchar(x%10+48);}
template <typename T> inline void write(T x){if(x<0){putchar('-');x=-x;}writep(x);putchar(' ');}
template <typename T> inline void writeln(T x){write(x);putchar('\n');}
using namespace std;
int n,s[maxn],top,bot,h[maxn];
vector <int> a[maxn];
long long ans = 1ll*maxc*maxc;
void Try(int st)
{
FOR(i,1,n) h[i] = 0;
h[st] = 1;
s[top = bot = 1] = st;
while (bot <= top)
{
int u = s[bot++];
for (int v : a[u])
if (!h[v])
{
h[v] = h[u] + 1;
s[++top] = v;
//cout << u << ' ' << v << '\n';
}
}
long long res = 0;
FOR(i,1,n)
if (!h[i]) return;
else res += h[i];
ans = min(ans,res);
}
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//freopen(Task".inp", "r",stdin);
//freopen(Task".out", "w",stdout);
cin >> n;
FOR(i,1,n)
{
int x,y;
cin >> x;
FOR(j,1,x)
{
cin >> y;
a[y].pb(i);
}
}
FOR(i,1,n) Try(i);
//Try(6);
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |