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>
#define FOR(x, a, b) for (int x = a; x <= b; ++x)
#define FOD(x, a, b) for (int x = a; x >= b; --x)
#define REP(x, a, b) for (int x = a; x < b; ++x)
#define DEBUG(X) { cout << #X << " = " << X << endl; }
#define PR(A, n) { cout << #A << " = "; FOR(_, 1, n) cout << A[_] << " "; cout << endl; }
#define PR0(A, n) { cout << #A << " = "; REP(_, 0, n) cout << A[_] << " "; cout << endl; }
using namespace std;
typedef long long LL;
typedef pair <int, int> II;
const int N = 5e3 + 10;
const int INF = 0x3f3f3f3f;
int n;
int f[N], p[N];
bool ban[N];
vector <int> boss[N], adj[N];
queue <int> Q;
int Compute(int u) {
FOR(i, 1, n) {
adj[i].clear();
p[i] = -1;
}
p[u] = 1;
Q.push(u);
int cnt = 0, ans = 0;
while (Q.size()) {
int u = Q.front(); Q.pop();
++cnt;
ans += p[u];
REP(k, 0, boss[u].size()) {
int v = boss[u][k];
if (p[v] == -1) {
p[v] = p[u] + 1;
Q.push(v);
}
}
}
if (cnt == n) return ans;
else return INF;
}
int main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif // LOCAL
scanf("%d", &n);
FOR(i, 1, n) {
int m; scanf("%d", &m);
FOR(j, 1, m) {
int x; scanf("%d", &x);
boss[x].push_back(i);
}
}
int ans = INF;
FOR(i, 1, n) ans = min(ans, Compute(i));
printf("%d\n", ans);
return 0;
}
Compilation message (stderr)
bosses.cpp: In function 'int Compute(int)':
bosses.cpp:5:40: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define REP(x, a, b) for (int x = a; x < b; ++x)
^
bosses.cpp:39:9: note: in expansion of macro 'REP'
REP(k, 0, boss[u].size()) {
^
bosses.cpp: In function 'int main()':
bosses.cpp:56:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
^
bosses.cpp:58:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int m; scanf("%d", &m);
^
bosses.cpp:60:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int x; scanf("%d", &x);
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |