# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
349306 |
2021-01-17T11:27:01 Z |
sinamhdv |
Bosses (BOI16_bosses) |
C++11 |
|
763 ms |
876 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int mod = 1000 * 1000 * 1000 + 7;
const int INF = 1000 * 1000 * 1000;
const ll LINF = (ll)INF * INF;
#ifdef DEBUG
#define dbg(x) cout << #x << " = " << (x) << endl << flush;
#define dbgr(s, f) { cout << #s << ": "; for (auto _ = (s); _ != (f); _++) cout << *_ << ' '; cout << endl << flush; }
#else
#define dbg(x) ;
#define dbgr(s, f) ;
#endif
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define fast_io ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define msub(a, b) ((mod + ((ll)(a) - (b)) % mod) % mod)
#define mdiv(a, b) ((ll)(a) * poww((b), mod - 2) % mod)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define endl '\n'
#define MAXN 5050
vector<int> cld[MAXN];
int h[MAXN];
ll ans = LINF;
int n;
bool mark[MAXN];
void bfs(int r)
{
memset(mark, 0, sizeof(mark));
fill(h, h + n + 5, INF);
h[r] = 0;
queue<int> q;
q.push(r);
mark[r] = true;
while (!q.empty())
{
int v = q.front();
q.pop();
for (int u : cld[v])
{
if (mark[u])
continue;
h[u] = h[v] + 1;
mark[u] = true;
q.push(u);
}
}
}
int32_t main(void)
{
fast_io;
cin >> n;
FOR(i, 1, n + 1)
{
int k;
cin >> k;
FOR(j, 0, k)
{
int x;
cin >> x;
cld[x].pb(i);
}
}
FOR(i, 1, n + 1)
{
bfs(i);
ll sm = 0;
bool ok = true;
FOR(i, 1, n + 1)
{
sm += h[i];
if (h[i] >= INF)
ok = false;
}
dbg(i);
dbgr(h + 1, h + n + 1);
if (ok)
ans = min(ans, sm);
}
cout << ans + n << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
492 KB |
Output is correct |
10 |
Correct |
1 ms |
508 KB |
Output is correct |
11 |
Correct |
1 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
492 KB |
Output is correct |
10 |
Correct |
1 ms |
508 KB |
Output is correct |
11 |
Correct |
1 ms |
492 KB |
Output is correct |
12 |
Correct |
4 ms |
620 KB |
Output is correct |
13 |
Correct |
3 ms |
620 KB |
Output is correct |
14 |
Correct |
156 ms |
620 KB |
Output is correct |
15 |
Correct |
39 ms |
748 KB |
Output is correct |
16 |
Correct |
589 ms |
740 KB |
Output is correct |
17 |
Correct |
736 ms |
876 KB |
Output is correct |
18 |
Correct |
763 ms |
876 KB |
Output is correct |