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;
int n;
vector< int > acc[5003];
int m;
int vis[5003];
int pa[5003];
vector<int> g[5003];
long long sal[5003];
long long res = LLONG_MAX;
long long dfs(int u, int root) {
long long cres = 1;
for (auto v : g[u]) {
cres += dfs(v, root);
}
sal[u] = cres;
if (u != root) return cres;
else {
cres = 0;
for (int i = 1; i <= n; i++) {
cres += sal[i];
if (cres > res) {
return LLONG_MAX;
}
}
return cres;
}
}
queue<int> q;
long long fouck(int pos) {
memset(vis, 0, sizeof(vis));
q.push(pos);
vis[pos] = 1;
for (int i = 1; i <= n; i++) {
g[i].clear();
}
int cnt = 0;
while (!q.empty()) {
cnt++;
int u = q.front(); q.pop();
for (auto v : acc[u]) {
if (!vis[v]) {
q.push(v);
g[u].push_back(v);
vis[v] = 1;
}
}
}
if (cnt == n) return dfs(pos, pos);
else {
return LLONG_MAX;
}
}
void fs(int &number) {
register int c;
number = 0;
c = getchar();
for (; (c>47 && c<58); c=getchar())
number = number *10 + c - 48;
}
signed main() {
int x, y;
fs(n);
for (int i = 1; i <= n; i++) {
fs(m);
for (int j = 1; j <= m; j ++) {
fs(x);
acc[x].push_back(i);
}
}
for (int i = 1; i <= n; i++) {
res = min(res, fouck(i));
}
cout << res;
}
Compilation message (stderr)
bosses.cpp: In function 'int main()':
bosses.cpp:69:9: warning: unused variable 'y' [-Wunused-variable]
int x, y;
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |