Submission #44912590
Source Code Expand
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0; i <(n);++i) using ll = long long; int main(){ ll n; cin >> n; vector<int> p(n); vector<int> c(n); vector<int> res(n, 1); for (int i = 1; i < n; ++i) { cin >> p[i]; p[i]--; c[p[i]]++; } vector<int> q; rep(i,n) { if (c[i] == 0) q.push_back(i); } while(!q.empty()) { int i = q.back(); q.pop_back(); if (i == 0) break; res[p[i]] += res[i]; if (--c[p[i]] == 0){ q.push_back(p[i]); } } for (int i = 0; i < n; ++i) { cout << res[i] << endl; } }
Submission Info
Submission Time | |
---|---|
Task | B - 部分木サイズ |
User | TumoiYorozu |
Language | C++ 23 (gcc 12.2) |
Score | 1 |
Code Size | 708 Byte |
Status | AC |
Exec Time | 569 ms |
Memory | 11136 KiB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 1 / 1 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample-01.txt, sample-02.txt |
All | 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, sample-01.txt, sample-02.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01-01.txt | AC | 548 ms | 10012 KiB |
01-02.txt | AC | 550 ms | 9996 KiB |
01-03.txt | AC | 569 ms | 9704 KiB |
01-04.txt | AC | 566 ms | 9664 KiB |
01-05.txt | AC | 497 ms | 11136 KiB |
sample-01.txt | AC | 1 ms | 3472 KiB |
sample-02.txt | AC | 1 ms | 3484 KiB |