| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 974799 | KasymK | Cat in a tree (BOI17_catinatree) | C++17 | 1018 ms | 3596 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
const int N = 1e5 + 5;
int n, d;
int mx = INT_MIN;
vector<int> adj[N], bit;
int vis[N], dis[N];
int in_yakyn(int id){
for(int i = 0; i < n; ++i)
vis[i] = dis[i] = 0;
queue<int> q;
q.push(id);
vis[id] = 1;
while(!q.empty()){
int x = q.front();
q.pop();
for(auto i : adj[x])
if(!vis[i]){
vis[i] = 1;
q.push(i);
dis[i] = dis[x] + 1;
if(bit[i])
return dis[i];
}
}
}
bool barla(){
int cnt = count(bit.begin(), bit.end(), 1);
if(cnt <= 1)
return 1;
for(int i = 0; i < n; ++i)
if(bit[i] and in_yakyn(i) < d)
return 0;
return 1;
}
void f(int x){
if(x == n){
int cnt = count(bit.begin(), bit.end(), 1);
if(barla())
mx = max(mx, cnt);
return;
}
for(int i = 0; i <= 1; ++i){
bit[x] = i;
f(x + 1);
}
}
int main(){
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n >> d;
for(int i = 1; i <= n - 1; ++i){
int x;
cin >> x;
adj[x].push_back(i);
adj[i].push_back(x);
}
bit.resize(n);
f(0);
cout << mx << "\n";
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... | ||||
