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>
#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
#define ull unsigned long long
#define unint unsigned int
#define sint short int
#define usint unsigned short int
#define ll long long
#define ld long double
#define vt vector
#define pb push_back
#define mp make_pair
#define PI 3.14159265358979323
#define F first
#define S second
#define all(a) (a).begin(), (a).end()
#define sz(a) ((int)a.size())
#define clr(x,a) memset(x, a, sizeof(x))
#define len(a) ((int)a.length())
#define E 2.7182818284590452353602874713527
#define FOR(i, x) for(int i=0; i<x; ++i)
#define For(i, x) for(auto& i: x)
#define RFOR(i, x) for(int i=x-1; i>=0; --i)
#define FORS(x, s, e, n) for(int x=s; x<=e; x+=n)
#define int long long
typedef pair<int, int> pii;
void solve(){
}
vector<int>adj[5005];
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int a;
cin >> a;
int temp;
for(int x=1;x<=a;x++){
int b;
cin >> b;
for(int y=1;y<=b;y++){
cin >> temp;
adj[temp].push_back(x);
}
}
//dfs
int best=INT_MAX;
queue<int> q;
bool visited[5005];
int distance[5005];
for(int x=1;x<=a;x++){
memset(visited,0,sizeof(visited));
memset(distance,0,sizeof(distance));
int maxD=0;
visited[x] = true;
distance[x] = 0;
q.push(x);
while (!q.empty()) {
int s = q.front(); q.pop();
// process node s
for (auto u : adj[s]) {
if (visited[u]) continue;
visited[u] = true;
distance[u] = distance[s]+1;
q.push(u);
}
}
int counter=0;
for(int y=1;y<=a;y++){
counter+=distance[y];
}
best=min(best,counter);
}
cout << best;
return 0;
}
Compilation message (stderr)
bosses.cpp: In function 'int32_t main()':
bosses.cpp:60:13: warning: unused variable 'maxD' [-Wunused-variable]
60 | int maxD=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... |