# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
58207 | PeppaPig | Bosses (BOI16_bosses) | C++14 | 1564 ms | 1352 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pii pair<int, int>
#define x first
#define y second
using namespace std;
const int N = 5e3 + 5;
int n, ans = INT_MAX;
vector<vector<int> > g(N);
int sal[N], par[N], dep[N];
bool vis[N];
int bfs(int root) {
int ret = 0;
queue<int> Q;
stack<int> S;
memset(vis, false, sizeof vis);
for(int i = 1; i <= n; i++) sal[i] = 1, dep[i] = INT_MAX;
Q.emplace(root);
par[root] = 0;
dep[root] = 1;
vis[root] = true;
while(!Q.empty()) {
int now = Q.front();
Q.pop();
S.emplace(now);
for(int v : g[now]) if(dep[now] + 1 < dep[v] && !vis[v]) {
vis[v] = true;
dep[v] = dep[now] + 1;
par[v] = now;
Q.emplace(v);
}
}
vector<pii> proc;
for(int i = 1; i <= n; i++) {
if(dep[i] == INT_MAX) return INT_MAX;
proc.emplace_back(dep[i], i);
}
sort(proc.begin(), proc.end(), [&](const pii &a, const pii &b) {
return a.x > b.x;
});
for(pii v : proc) sal[par[v.y]] += sal[v.y];
for(int i = 1; i <= n; i++) ret += sal[i];
return ret;
}
int main() {
scanf("%d", &n);
for(int i = 1, k; i <= n; i++) {
scanf("%d", &k);
while(k--) {
int v;
scanf("%d", &v);
g[v].emplace_back(i);
}
}
for(int i = 1; i <= n; i++) ans = min(ans, bfs(i));
printf("%d", ans);
return 0;
}
컴파일 시 표준 에러 (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... |