| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 907726 | shoryu386 | Cat in a tree (BOI17_catinatree) | C++17 | 1008 ms | 22088 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<int> adj[200007];
int depth[200007];
bitset<200007> marked;
void dfs(int x, int p, int d){
depth[x] = d;
for (auto y : adj[x]){
if (y == p) continue;
dfs(y, x, d+1);
}
}
int dfsMarked(int x, int p){
int ans = INT_MAX;
if (marked[x]) return 0;
for (auto y : adj[x]){
if (y == p) continue;
ans = min(dfsMarked(y, x) + 1, ans);
}
return ans;
}
main(){
int n, d; cin >> n >> d;
int p[n];
for (int x = 1; x < n; x++){
cin >> p[x];
adj[x].push_back(p[x]);
adj[p[x]].push_back(x);
}
dfs(0, -1, 0);
vector<int> depthOrder[200007];
for (int x = 0; x < n; x++){
depthOrder[depth[x]].push_back(x);
}
int ans = 0;
for (int x = 200000; x > -1; x--){
for (auto y : depthOrder[x]){
//cout << y << ' ' << dfsMarked(y, -1) << '\n';
if (dfsMarked(y, -1) >= d){
marked[y] = 1;
ans++;
}
//cout << y << ' ' << marked[y] << '\n';
}
}
cout << ans;
}
컴파일 시 표준 에러 (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... | ||||
