# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1255246 | hoa208 | Bosses (BOI16_bosses) | C++20 | 368 ms | 796 KiB |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define FORD(i, b, a) for (int i = (b), _a = (a); i >= _a; i--)
#define pa pair<ll, ll>
#define fi first
#define se second
#define bit(mask, j) ((mask >> j) & 1)
#define t_test int t;cin >> t;while(t--)
const ll mod = 1e9 + 7;
const ll INF = 1e18;
inline void adm(ll &x){if(x>=mod)x%=mod;else if(x<0)x+=mod;}
//--------------------------------------------------------------------
const int N = 5003;
int h[N], a[N];
ll dp[N];
vector<int> g[N];
int n;
ll bfs(int s) {
queue<int> q;
FOR(i, 1, n) h[i] = 0, dp[i] = 0;
q.push(s);
h[s] = -1;
int m = 0;
while(!q.empty()) {
ll u = q.front();
q.pop();
a[++m] = u;
for(auto v : g[u]) {
if(h[v] != 0) continue;
h[v] = u;
q.push(v);
}
}
if(m != n) return INF;
ll ans = 0;
FORD(i, m, 1) {
int v = a[i];
dp[v]++;
ans += dp[v];
dp[h[v]] += dp[v];
}
return ans;
}
void hbmt() {
cin >> n;
FOR(i, 1, n) {
int m;
cin >> m;
while(m--) {
int x;
cin >> x;
g[x].push_back(i);
}
}
ll ans = INF;
FOR(i, 1, n) {
ans = min(ans, bfs(i));
}
cout << ans;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
if(fopen("hbmt.inp", "r")) {
freopen("hbmt.inp", "r", stdin);
freopen("hbmt.out", "w", stdout);
}
// t_test
hbmt();
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |