# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
342969 |
2021-01-03T09:51:45 Z |
leinad2 |
Village (BOI20_village) |
C++17 |
|
2 ms |
2668 KB |
#include<bits/stdc++.h>
using namespace std;
int n, i, j, k, a, b, ans[100010], A[100010], res, cent, sz[100010], dep[100010], in[100010], cnt;
vector<int>adj[100010];
void dfs(int v, int par, int depth)
{
in[v]=++cnt;
dep[v]=depth;
sz[v]=1;
for(int i=0;i<adj[v].size();i++)
{
int p=adj[v][i];
if(p==par)continue;
dfs(p, v, depth+1);
sz[v]+=sz[p];
}
}
int centroid(int v, int par)
{
for(int i=0;i<adj[v].size();i++)
{
int p=adj[v][i];
if(p==par)continue;
if(sz[p]*2>sz[v])
{
return centroid(p, v);
}
}
return v;
}
int f(int x)
{
return ((x+(n/2))%n==0?n:(x+(n/2))%n);
}
int main()
{
for(scanf("%d", &n);++i<n;)
{
scanf("%d %d", &a, &b);
adj[a].push_back(b);
adj[b].push_back(a);
}
dfs(1, 0, 0);
cent=centroid(1, 0);
cnt=0;
dfs(cent, 0, 0);
for(i=0;i++<n;)res+=dep[i]*2;
for(i=0;i++<n;)
{
ans[in[i]]=in[f(i)];
}
printf("0 %d\n", res);
for(i=0;i++<n;)printf("0 ");
puts("");
for(i=0;i++<n;)
{
printf("%d ", ans[i]);
}
}
Compilation message
Village.cpp: In function 'void dfs(int, int, int)':
Village.cpp:10:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
10 | for(int i=0;i<adj[v].size();i++)
| ~^~~~~~~~~~~~~~
Village.cpp: In function 'int centroid(int, int)':
Village.cpp:20:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | for(int i=0;i<adj[v].size();i++)
| ~^~~~~~~~~~~~~~
Village.cpp: In function 'int main()':
Village.cpp:37:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
37 | for(scanf("%d", &n);++i<n;)
| ~~~~~^~~~~~~~~~
Village.cpp:39:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
39 | scanf("%d %d", &a, &b);
| ~~~~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2668 KB |
Integer parameter [name=vi] equals to 0, violates the range [1, 4] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2668 KB |
Integer parameter [name=vi] equals to 0, violates the range [1, 256] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2668 KB |
Integer parameter [name=vi] equals to 0, violates the range [1, 4] |
2 |
Halted |
0 ms |
0 KB |
- |