This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, ll>
#define p3l pair<pll, ll>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define MN 1000000007
#define fox(k, x) for (int k=0; k<x; ++k)
#define fox1(k, x) for (int k=1; k<=x; ++k)
#define foxr(k, x) for (int k=x-1; k>=0; --k)
#define fox1r(k, x) for (int k=x; k>0; --k)
#define ms multiset
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)
#define rng() (rand() >> 3)*rand()
int n, k, a, N, D, c;
int tmp, ans = (1 << 30);
vector<int> v[5005];
queue<pii> q;
bool u[5005];
void bfs(int R){
drain(u); c=0; tmp=0;
q.push(mp(R, 0));
while(!q.empty()){
N=q.front().x; D=q.front().y; q.pop();
if (u[N]) continue;
u[N]=1;
c++;
tmp+=D+1;
//cout << D << endl;
fox(l, v[N].size()){
q.push(mp(v[N][l], D+1));
}
}
//cout << endl;
if (c==n) ans=min(ans, tmp);
}
int main(){
cin >> n;
fox1(l, n){
cin >> k;
fox(l2, k){
cin >> a;
v[a].pb(l);
}
}
fox1(l, n) bfs(l);
cout << ans;
return 0;
}
Compilation message (stderr)
bosses.cpp: In function 'void bfs(int)':
bosses.cpp:18:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define fox(k, x) for (int k=0; k<x; ++k)
^
bosses.cpp:42:9: note: in expansion of macro 'fox'
fox(l, v[N].size()){
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |