# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
503700 |
2022-01-08T15:41:03 Z |
banterbry |
Bosses (BOI16_bosses) |
C++17 |
|
1500 ms |
1052 KB |
// Factos 👍👀
#undef _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define pb push_back
#define fi first
#define si second
#define ar array
typedef pair<int,int> pi;
typedef tuple<int,int,int> ti;
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {cerr << " " << to_string(H);debug_out(T...);}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
int N, ans = (1<<30), vis[5010], dp[5010];
vector<int> adj[5010], go[5010];
vector<int> order;
queue<int> q;
void dfs(int x) {
for (auto i: go[x]) {
dfs(i);
}
order.pb(x);
}
int32_t main() {
fast;
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].pb(i);
}
}
for (int i = 1; i <= N; ++i) {
for (int j = 1; j <= N; ++j) go[j].clear();
memset(vis, 0, sizeof vis);
order.clear();
q.push(i);
vis[i] = 1;
while (q.size()) {
int x = q.front(); q.pop();
for (auto v: adj[x]) {
if (vis[v]) continue;
vis[v] = 1;
go[x].pb(v);
q.push(v);
}
}
bool skip = false;
for (int j = 1; j <= N; ++j) {
if (!vis[j]) skip = true;
}
if (skip) continue;
dfs(i);
memset(dp, 0, sizeof dp);
int cur = 0;
for (auto i: order) {
int sum = 0;
for (auto j: go[i]) sum += dp[j];
dp[i] = sum + 1;
cur += dp[i];
}
ans = min(ans, cur);
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
588 KB |
Output is correct |
2 |
Correct |
1 ms |
588 KB |
Output is correct |
3 |
Correct |
0 ms |
588 KB |
Output is correct |
4 |
Correct |
1 ms |
588 KB |
Output is correct |
5 |
Correct |
0 ms |
588 KB |
Output is correct |
6 |
Correct |
0 ms |
588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
588 KB |
Output is correct |
2 |
Correct |
1 ms |
588 KB |
Output is correct |
3 |
Correct |
0 ms |
588 KB |
Output is correct |
4 |
Correct |
1 ms |
588 KB |
Output is correct |
5 |
Correct |
0 ms |
588 KB |
Output is correct |
6 |
Correct |
0 ms |
588 KB |
Output is correct |
7 |
Correct |
1 ms |
588 KB |
Output is correct |
8 |
Correct |
1 ms |
588 KB |
Output is correct |
9 |
Correct |
1 ms |
588 KB |
Output is correct |
10 |
Correct |
1 ms |
588 KB |
Output is correct |
11 |
Correct |
1 ms |
588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
588 KB |
Output is correct |
2 |
Correct |
1 ms |
588 KB |
Output is correct |
3 |
Correct |
0 ms |
588 KB |
Output is correct |
4 |
Correct |
1 ms |
588 KB |
Output is correct |
5 |
Correct |
0 ms |
588 KB |
Output is correct |
6 |
Correct |
0 ms |
588 KB |
Output is correct |
7 |
Correct |
1 ms |
588 KB |
Output is correct |
8 |
Correct |
1 ms |
588 KB |
Output is correct |
9 |
Correct |
1 ms |
588 KB |
Output is correct |
10 |
Correct |
1 ms |
588 KB |
Output is correct |
11 |
Correct |
1 ms |
588 KB |
Output is correct |
12 |
Correct |
5 ms |
844 KB |
Output is correct |
13 |
Correct |
8 ms |
844 KB |
Output is correct |
14 |
Correct |
229 ms |
1008 KB |
Output is correct |
15 |
Correct |
53 ms |
836 KB |
Output is correct |
16 |
Correct |
753 ms |
1052 KB |
Output is correct |
17 |
Execution timed out |
1518 ms |
1016 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |