// compile: make data
// run: ./data < data.in
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#ifdef LOCAL
#include <debug/codeforces.h>
#define debug(x...) _debug_print(#x, x);
#define Debug(x...) _debug_print_format(#x, x);
#else
#define debug(x...)
#define Debug(x...)
#endif
template<typename...Args> void print_(Args...args){((cout<<args<<" "),...)<<endl;}
#define VI vector<int>
#define VII vector<vector<int>>
#define VIII vector<vector<vector<int>>>
#define rep(i,a,b) for(int i=(a);i<(int)(b);++i)
#define sz(v) ((int)(v).size())
#define print(...) print_(__VA_ARGS__);
#define FIND(a, x) ((find(a.begin(),a.end(),(x))!=a.end())?1:0)
#define cmin(x,...) x=min({(x), __VA_ARGS__})
#define cmax(x,...) x=max({(x), __VA_ARGS__})
#define INTMAX (int)(9223372036854775807)
#define INF (int)(1152921504606846976)
#define NaN (int)(0x8b88e1d0595d51d1)
#define double long double
#define int long long
#define MAXN 200010
struct Tree {
int n;
vector<vector<int>> el;
struct node {
vector<node*> ch;
node* parent;
int size;
};
vector<node> vertex;
node *root;
Tree(int V) {
n = V;
el.resize(n);
vertex.resize(n);
}
void add_edge(int u, int v) {
el[u].push_back(v), el[v].push_back(u);
}
void build(int rt = 0) {
function<void(int, int)> dfs = [&](int u, int pre) {
vertex[u].size = 1;
for (int v: el[u]) {
if (v == pre) continue;
vertex[u].ch.push_back(&vertex[v]);
vertex[v].parent = &vertex[u];
dfs(v, u);
vertex[u].size += vertex[v].size;
}
};
root = &vertex[rt];
dfs(rt, -1);
}
void graphviz_dump(int plus = 0, string filename = "graph.dot") {
FILE *f = fopen(filename.c_str(), "w");
fprintf(f, "digraph Tree {\n");
rep(i, 0, n) {
node *x = &vertex[i];
fprintf(f, " %lld;\n");
}
rep(i, 0, n) {
node *x = &vertex[i];
for (auto y: x->ch) {
fprintf(f, " %ld -> %ld;\n", x - &vertex[0], y - &vertex[0]);
}
}
fprintf(f, "}\n");
}
};
int32_t main() {
ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
int n; cin >> n;
Tree t(n);
rep(i, 0, n-1) {
int x; cin >> x;
t.add_edge(i+1, x-1);
}
t.build(0);
rep(i, 0, n) cout << t.vertex[i].size-1 << " \n"[i==n-1];
t.graphviz_dump(1);
return 0;
}
Right then, 89kbetvn. Decent site for a punt. Nothing overly spectacular, but it does the job. If you fancy a quick flutter, why not? Check it out: 89kbetvn
Calling all iOS users! 88vinproios looks like the go-to app for 88vin. If you’re on iPhone, this is a must-have. Go there NOW at 88vinproios!
Looking for some games to download? VipGameDownload has a few options, but do your research before downloading anything. Safety first, always! Check them out at vipgamedownload.
Hey, did anyone check the ‘nesine çekiliş sonuçları’ yet? I’m always hoping for a win. Fingers crossed! Check it out here: nesine çekiliş sonuçları
The Plot777 slot games? They seem pretty fun. You can try them. It’s a site that has games. Check plot777 slot on plot777loginregister.com, good luck spinning!
OKBET doing motor racing betting, huh? That’s my kinda action! Need to see what odds they’re offering. Get on track with okbet motor racing betting.
Yo, m88a2hercules is where it’s at! Seriously, if you’re looking for some action, this is the place. I’ve been hooked for weeks now. Worth a look m88a2hercules.
So i have come across a33clubgame, has anyone played before? please share your experience with me: a33clubgame
Weathernoho… Now that’s a specific one! Weather in NoHo? I’m checking this before my next trip! I’ll be equipped with the information I need when I visit! Check it out here: weathernoho