This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*************************************************************************
* *
* XX Olimpiada Informatyczna *
* *
* Zadanie: Luk triumfalny *
* Autor: Karol Pokorski *
* Zlozonosc czasowa: O(n^2) *
* Zlozonosc pamieciowa: O(n) *
* Opis: Rozwiazanie wolne *
* *
*************************************************************************/
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
const int MAXN = 1000001;
vector<int> adj[MAXN];
bool visited[MAXN];
int a = 0;
int Check(int u, int k,int height) {
if(height>=a)a = height;
int numChildren = 0, sumTree = 0;
visited[u] = true;
for (int i = 0; i < (int)adj[u].size(); i++)
if (!visited[adj[u][i]]) {
numChildren++;
sumTree += Check(adj[u][i], k,height+1);
}
return max(0, numChildren+sumTree);
}
int main() {
int N, ret;
ret = scanf("%d", &N);
if (ret < 0)
return 0;
for (int i = 0; i < N-1; i++) {
int u, v;
ret = scanf("%d%d", &u, &v);
u--;
v--;
adj[u].push_back(v);
adj[v].push_back(u);
}
for (int i = 0; i <= N; i++) {
fill(visited, visited+N, false);
int tmp = Check(0, i,0);
if(a!=0){
if (tmp%a == 0 &&tmp/a == i) {
printf("%d\n", i);
return 0;
}
}
}
return 0;
}
# | 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... |