# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
484211 |
2021-11-02T13:47:22 Z |
Sohsoh84 |
Bosses (BOI16_bosses) |
C++17 |
|
16 ms |
27716 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define X first
#define Y second
#define sep ' '
#define endl '\n'
#define debug(x) cerr << #x << ": " << x << endl;
const ll MAXN = 1e6 + 10;
int n, dist[MAXN];
vector<int> adj[MAXN];
inline ll calc(int v) {
memset(dist, 63, sizeof dist);
queue<int> q;
q.push(v);
dist[v] = 1;
ll ans = 0;
while (!q.empty()) {
v = q.front();
q.pop();
ans += dist[v];
for (int u : adj[v]) {
if (dist[v] + 1 < dist[u]) {
dist[u] = dist[v] + 1;
q.push(u);
}
}
}
return ans;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
int k;
cin >> k;
for (int j = 0; j < k; j++) {
int x;
cin >> x;
adj[x].push_back(i);
}
}
ll ans = MAXN * MAXN;
for (int i = 1; i <= n; i++)
ans = min(ans, calc(i));
cout << ans << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
27716 KB |
Output is correct |
2 |
Correct |
15 ms |
27612 KB |
Output is correct |
3 |
Incorrect |
16 ms |
27704 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
27716 KB |
Output is correct |
2 |
Correct |
15 ms |
27612 KB |
Output is correct |
3 |
Incorrect |
16 ms |
27704 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
27716 KB |
Output is correct |
2 |
Correct |
15 ms |
27612 KB |
Output is correct |
3 |
Incorrect |
16 ms |
27704 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |