# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1263633 | mingga | Bosses (BOI16_bosses) | C++20 | 392 ms | 776 KiB |
#include "bits/stdc++.h"
using namespace std;
#define ln "\n"
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define int long long
const int mod = 1e9 + 7;
const int inf = 2e18;
const int N = 5005;
vector<int> g[N];
int d[N];
int n;
signed main() {
cin.tie(0) -> sync_with_stdio(0);
#define task ""
if(fopen(task ".INP", "r")) {
freopen(task ".INP", "r", stdin);
freopen(task ".OUT", "w", stdout);
}
cin >> n;
for(int i = 1; i <= n; i++) {
int k; cin >> k;
while(k--) {
int x; cin >> x;
g[x].pb(i);
}
}
int ans = inf;
for(int i = 1; i <= n; i++) {
queue<int> q;
q.push(i);
memset(d, 0, sizeof d);
d[i] = 1;
int cur = 0;
int cnt = 0;
// cerr << "TURN " << i << ln;
while(sz(q)) {
int u = q.front(); q.pop();
cur += d[u];
cnt++;
for(int v : g[u]) {
if(d[v] == 0) {
// cerr << u << ' ' << v << ln;
d[v] = d[u] + 1;
q.push(v);
}
}
}
if(cnt < n) continue;
ans = min(ans, cur);
}
cout << ans << ln;
cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC;
}
컴파일 시 표준 에러 (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... |