# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
218609 | Ruxandra985 | Bosses (BOI16_bosses) | C++14 | 5 ms | 512 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define DIMN 5010
using namespace std;
priority_queue <pair <int,int> > h;
vector <int> v[DIMN];
int d[DIMN] , tt[DIMN] , lvl[DIMN] , under[DIMN];
int dfs (int nod){
int i , vecin , sol = 0;
d[nod] = 1;
for (i = 0 ; i < v[nod].size() ; i++){
vecin = v[nod][i];
if (tt[vecin] == nod){
sol += dfs(vecin);
d[nod] += d[vecin];
}
}
return sol + d[nod];
}
int main()
{
FILE *fin = stdin;
FILE *fout = stdout;
int n , i , k , x , sol , root , nod , vecin , niv , j;
fscanf (fin,"%d",&n);
for (i = 1 ; i <= n ; i++){
fscanf (fin,"%d",&k);
for (j = 1 ; j <= k ; j++){
fscanf (fin,"%d",&x);
v[x].push_back(i); /// x poate fi seful lui i
}
}
sol = 2000000000;
for (root = 1 ; root <= n ; root++){
h.push(make_pair(-1 , root));
memset (lvl , 0 , sizeof(lvl));
memset (under , 0 , sizeof(under));
lvl[root] = 1;
tt[root] = 0;
while (!h.empty()){
nod = h.top().second;
niv = -h.top().first;
h.pop();
if (lvl[nod] != niv)
continue;
for (i = 0 ; i < v[nod].size() ; i++){
vecin = v[nod][i];
if (lvl[vecin] == 0 || lvl[vecin] > lvl[nod] + 1){
lvl[vecin] = lvl[nod] + 1;
under[tt[vecin]]--;
under[nod]++;
tt[vecin] = nod;
h.push(make_pair(-lvl[vecin] , vecin));
}
else if (lvl[vecin] == lvl[nod] + 1 && under[nod] < under[tt[vecin]]){
lvl[vecin] = lvl[nod] + 1;
under[tt[vecin]]--;
under[nod]++;
tt[vecin] = nod;
h.push(make_pair(-lvl[vecin] , vecin));
}
}
}
sol = min(sol , dfs(root));
}
fprintf (fout,"%d",sol);
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... |