#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], revin[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>n)
{
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;)
{
revin[in[i]]=i;
}
for(i=0;i++<n;)
{
ans[revin[i]]=revin[f(i)];
}
printf("1 %d\n", res);
for(i=0;i++<n;)printf("1 ");
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);
| ~~~~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
2 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
3 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
4 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
5 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
6 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
7 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
8 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
9 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
10 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
11 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
12 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
13 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
14 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
15 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
16 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
17 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
2 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
3 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
4 |
Partially correct |
3 ms |
2796 KB |
Partially correct |
5 |
Partially correct |
3 ms |
2796 KB |
Partially correct |
6 |
Partially correct |
3 ms |
2796 KB |
Partially correct |
7 |
Partially correct |
3 ms |
2796 KB |
Partially correct |
8 |
Partially correct |
3 ms |
2796 KB |
Partially correct |
9 |
Partially correct |
3 ms |
2796 KB |
Partially correct |
10 |
Partially correct |
3 ms |
2796 KB |
Partially correct |
11 |
Partially correct |
3 ms |
2796 KB |
Partially correct |
12 |
Partially correct |
3 ms |
2796 KB |
Partially correct |
13 |
Partially correct |
2 ms |
2796 KB |
Partially correct |
14 |
Partially correct |
3 ms |
2796 KB |
Partially correct |
15 |
Partially correct |
2 ms |
2796 KB |
Partially correct |
16 |
Partially correct |
3 ms |
2796 KB |
Partially correct |
17 |
Partially correct |
3 ms |
2796 KB |
Partially correct |
18 |
Partially correct |
2 ms |
2796 KB |
Partially correct |
19 |
Partially correct |
2 ms |
2796 KB |
Partially correct |
20 |
Partially correct |
2 ms |
2796 KB |
Partially correct |
21 |
Partially correct |
3 ms |
2796 KB |
Partially correct |
22 |
Partially correct |
2 ms |
2796 KB |
Partially correct |
23 |
Partially correct |
2 ms |
2796 KB |
Partially correct |
24 |
Partially correct |
3 ms |
2796 KB |
Partially correct |
25 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
26 |
Partially correct |
3 ms |
2796 KB |
Partially correct |
27 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
28 |
Partially correct |
3 ms |
2796 KB |
Partially correct |
29 |
Partially correct |
3 ms |
2796 KB |
Partially correct |
30 |
Partially correct |
2 ms |
2796 KB |
Partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
2 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
3 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
4 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
5 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
6 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
7 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
8 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
9 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
10 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
11 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
12 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
13 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
14 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
15 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
16 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
17 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
18 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
19 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
20 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
21 |
Partially correct |
3 ms |
2796 KB |
Partially correct |
22 |
Partially correct |
3 ms |
2796 KB |
Partially correct |
23 |
Partially correct |
3 ms |
2796 KB |
Partially correct |
24 |
Partially correct |
3 ms |
2796 KB |
Partially correct |
25 |
Partially correct |
3 ms |
2796 KB |
Partially correct |
26 |
Partially correct |
3 ms |
2796 KB |
Partially correct |
27 |
Partially correct |
3 ms |
2796 KB |
Partially correct |
28 |
Partially correct |
3 ms |
2796 KB |
Partially correct |
29 |
Partially correct |
3 ms |
2796 KB |
Partially correct |
30 |
Partially correct |
2 ms |
2796 KB |
Partially correct |
31 |
Partially correct |
3 ms |
2796 KB |
Partially correct |
32 |
Partially correct |
2 ms |
2796 KB |
Partially correct |
33 |
Partially correct |
3 ms |
2796 KB |
Partially correct |
34 |
Partially correct |
3 ms |
2796 KB |
Partially correct |
35 |
Partially correct |
2 ms |
2796 KB |
Partially correct |
36 |
Partially correct |
2 ms |
2796 KB |
Partially correct |
37 |
Partially correct |
2 ms |
2796 KB |
Partially correct |
38 |
Partially correct |
3 ms |
2796 KB |
Partially correct |
39 |
Partially correct |
2 ms |
2796 KB |
Partially correct |
40 |
Partially correct |
2 ms |
2796 KB |
Partially correct |
41 |
Partially correct |
3 ms |
2796 KB |
Partially correct |
42 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
43 |
Partially correct |
3 ms |
2796 KB |
Partially correct |
44 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
45 |
Partially correct |
3 ms |
2796 KB |
Partially correct |
46 |
Partially correct |
3 ms |
2796 KB |
Partially correct |
47 |
Partially correct |
2 ms |
2796 KB |
Partially correct |
48 |
Partially correct |
76 ms |
9196 KB |
Partially correct |
49 |
Partially correct |
116 ms |
9836 KB |
Partially correct |
50 |
Partially correct |
88 ms |
9836 KB |
Partially correct |
51 |
Partially correct |
68 ms |
8428 KB |
Partially correct |
52 |
Partially correct |
101 ms |
9836 KB |
Partially correct |
53 |
Partially correct |
80 ms |
9196 KB |
Partially correct |
54 |
Partially correct |
57 ms |
9836 KB |
Partially correct |
55 |
Incorrect |
106 ms |
17260 KB |
Output isn't correct |
56 |
Halted |
0 ms |
0 KB |
- |