이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//
// main.cpp
// IntensiveCamp 2 2024
//
// Created by Ali AlSalman on 17/05/2024.
//
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
struct segment_tree {
private:
int _offset;
vector<int> _data;
int _query(int u, int l, int r, int qlow, int qhi) {
if (qlow <= l && r <= qhi) return _data[u];
else if (r <= qlow || qhi <= l) return 0;
else {
int m = (l + r) / 2;
return _query(u * 2, l, m, qlow, qhi) *
_query(u * 2 + 1, m, r, qlow, qhi);
}
}
public:
segment_tree(int n) {
if (__builtin_popcount(n) == 1) _offset = n;
else _offset = (1<<(32 - __builtin_clz(n)));
_data.resize(_offset * 2);
}
segment_tree(vector<int>::iterator begin, vector<int>::iterator end) {
}
void inc(int i, int val = 1) {
for (i += _offset; i; i /= 2) _data[i] += val;
}
void inc(pair<int, int> range) {
auto &[l, r] = range;
l += _offset; r += _offset;
this->inc(l);
this->inc(r, -1);
}
int query(int l, int r) {
return _query(0, 0, _offset, l, r);
}
};
vector<int> depths;
vector<vector<int>> children;
void dfs(int u = 1, int p = -1, int d = 1) {
depths[d]++;
for (int child : children[u]) if (child != p) {
dfs(child, u, d + 1);
}
}
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
int n;
cin>>n; children.resize(n + 1); depths.resize(n + 1);
for (int i = 1; i < n; i++) {
int a, b;
cin>>a>>b;
children[a].push_back(b);
children[b].push_back(a);
}
dfs();
auto it = find(depths.begin() + 2, depths.end(), 0);
int ans = accumulate(depths.begin() + 2, it, 0) / distance(depths.begin() + 2, it);
cout<<ans<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |