| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1121359 | ezdp | Cat in a tree (BOI17_catinatree) | C++14 | 1 ms | 340 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5;
template<class T> using matrix = vector<vector<T>>;
matrix<int> G;
int n, d, depths[MAXN + 5], block[MAXN + 5], par[MAXN + 5];
priority_queue<pair<int, int>> pq;
void dfs(int u = 1, int d = 0){
depths[u] = d;
for(auto v : G[u]){
dfs(v, d + 1);
}
}
void dfs_block(int u, int d){
if(d == 0 || block[u]) return;
block[u] = true;
if(u != 1) dfs_block(par[u], d - 1);
for(auto v : G[u]){
dfs_block(v, d - 1);
}
}
int main(){
cin >> n >> d;
G = matrix<int>(n + 1);
for(int i = 2; i <= n; i ++){
cin >> par[i]; ++ par[i];
G[par[i]].push_back(i);
}
dfs();
for(int u = 1; u <= n; u ++){
pq.push({depths[u], u});
}
int ans = 0;
while(!pq.empty()){
auto [_, u] = pq.top(); pq.pop();
if(block[u]) continue;
++ ans;
dfs_block(u, d);
}
cout << ans << endl;
}컴파일 시 표준 에러 (stderr) 메시지
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
