이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <climits>
#include <cmath>
#include <fstream>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
#define ll long long
//cin.tie(0);ios_base::sync_with_stdio(0);
const int MAXN = 3 * 1e5 + 5;
vector<int> adjList[MAXN];
int par[MAXN];
int n;
bool good;
void dfs(int src) {
for (auto i : adjList[src]) {
if (i == par[src]) {
continue;
}
par[i] = src;
dfs(i);
}
}
void check(int src, int mid, int val) {
val += mid;
val -= adjList[src].size();
if (src != 0) {
val++;
}
if (val < 0) {
good = false;
}
for (auto i : adjList[src]) {
if (i == par[src]) {
continue;
}
check(i, mid, val);
}
}
int main() {
cin >> n;
par[0] = 0;
for (int i = 0; i < n - 1; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
adjList[a].push_back(b);
adjList[b].push_back(a);
}
dfs(0);
int lo = 0, hi = n;
while (lo < hi) {
int mid = (lo + hi) / 2;
good = true;
check(0, mid, 0);
if (good) {
hi = mid;
}
else {
lo = mid + 1;
}
}
cout << lo << 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... |