This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
int 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++;
}
for (auto i : adjList[src]) {
if (i == par[src]) {
continue;
}
check(i, mid, min(0, val));
}
if (src == 0) {
good = 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 == 0) {
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... |