이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define taskname "test"
#define fi first
#define se second
#define pb push_back
#define faster ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
using ll = long long;
using pii = pair <int, int>;
using pil = pair <int, ll>;
using pli = pair <ll, int>;
using pll = pair <ll, ll>;
using ull = unsigned ll;
mt19937 Rand(chrono::steady_clock::now().time_since_epoch().count());
ll min(const ll &a, const ll &b){
return (a < b) ? a : b;
}
ll max(const ll &a, const ll &b){
return (a > b) ? a : b;
}
//const ll Mod = 1000000009;
//const ll Mod2 = 999999999989;
//only use when required
const int maxN = 2e5 + 1;
int n, d;
int depth[maxN];
int a[maxN];
int deg[maxN];
vector <int> adj[maxN];
bool visited[maxN];
void predfs(int u, int p){
for (const int &i: adj[u]){
if (i == p) continue;
depth[i] = depth[u] + 1;
predfs(i, u);
}
}
void dfs(int u, int p, int d){
visited[u] = 1;
if (d <= deg[u]) return;
deg[u] = d;
for (const int &i: adj[u]){
if (i == p) continue;
dfs(i, u, d - 1);
}
}
void Init(){
cin >> n >> d;
for (int i = 1; i < n; ++i){
int u; cin >> u;
adj[u].pb(i);
adj[i].pb(u);
}
predfs(0, 0);
iota(a, a + n, 0);
sort(a, a + n,[](const auto &i, const auto &j){
return depth[i] > depth[j];
});
int ans = 0;
for (int i = 0; i < n; ++i){
if (!deg[a[i]]){
dfs(a[i], a[i], d);
++ans;
}
}
cout << ans;
}
int main(){
if (fopen(taskname".inp", "r")){
freopen(taskname".inp", "r", stdin);
//freopen(taskname".out", "w", stdout);
}
faster;
ll tt = 1;
//cin >> tt;
while (tt--){
Init();
}
}
컴파일 시 표준 에러 (stderr) 메시지
catinatree.cpp: In function 'int main()':
catinatree.cpp:78:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
78 | freopen(taskname".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |