# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
342993 |
2021-01-03T10:34:49 Z |
leinad2 |
Village (BOI20_village) |
C++17 |
|
167 ms |
21612 KB |
#include<bits/stdc++.h>
#define int long long
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, res2, ans2[100010];
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);
}
void dfs2(int v, int par)
{
vector<int>V;
for(int i=0;i<adj[v].size();i++)
{
int p=adj[v][i];
if(p==par)continue;
dfs2(p, v);
if(!A[p])V.push_back(p);
}
if(v==1&&V.size()==0)
{
ans2[ans2[adj[v][0]]]=1;
ans2[1]=adj[v][0];
res2+=2;
return;
}
if(v==1&&V.size()==2)
{
res2+=4;
ans2[v]=V[0];
ans2[V[0]]=V[1];
ans2[V[1]]=v;
return;
}
if(V.size())
{
if(V.size()==2)
{
ans2[V[0]]=V[1];
ans2[V[1]]=V[0];
res2+=4;
}
else
{
A[v]=1;
ans2[V[0]]=v;
ans2[v]=V[0];
res2+=2;
if(V.size()>1)
{
for(i=1;i<V.size()-1;i++)
{
ans2[V[i]]=V[i+1];
res2+=2;
}
ans2[V.back()]=V[1];
res2+=2;
}
}
}
}
main()
{
for(scanf("%lld", &n);++i<n;)
{
scanf("%lld %lld", &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);
dfs2(1, 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("%lld %lld\n", res2, res);
for(i=0;i++<n;)printf("%lld ", ans2[i]);
puts("");
for(i=0;i++<n;)
{
printf("%lld ", ans[i]);
}
}
Compilation message
Village.cpp: In function 'void dfs(long long int, long long int, long long int)':
Village.cpp:11:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
11 | for(int i=0;i<adj[v].size();i++)
| ~^~~~~~~~~~~~~~
Village.cpp: In function 'long long int centroid(long long int, long long int)':
Village.cpp:21:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | for(int i=0;i<adj[v].size();i++)
| ~^~~~~~~~~~~~~~
Village.cpp: In function 'void dfs2(long long int, long long int)':
Village.cpp:39:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | for(int i=0;i<adj[v].size();i++)
| ~^~~~~~~~~~~~~~
Village.cpp:77:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
77 | for(i=1;i<V.size()-1;i++)
| ~^~~~~~~~~~~
Village.cpp: At global scope:
Village.cpp:88:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
88 | main()
| ^
Village.cpp: In function 'int main()':
Village.cpp:90:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
90 | for(scanf("%lld", &n);++i<n;)
| ~~~~~^~~~~~~~~~~~
Village.cpp:92:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
92 | scanf("%lld %lld", &a, &b);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2668 KB |
Output is correct |
2 |
Correct |
2 ms |
2668 KB |
Output is correct |
3 |
Correct |
2 ms |
2668 KB |
Output is correct |
4 |
Correct |
2 ms |
2668 KB |
Output is correct |
5 |
Correct |
2 ms |
2668 KB |
Output is correct |
6 |
Correct |
2 ms |
2668 KB |
Output is correct |
7 |
Correct |
2 ms |
2668 KB |
Output is correct |
8 |
Correct |
2 ms |
2668 KB |
Output is correct |
9 |
Correct |
2 ms |
2668 KB |
Output is correct |
10 |
Correct |
2 ms |
2668 KB |
Output is correct |
11 |
Correct |
2 ms |
2668 KB |
Output is correct |
12 |
Correct |
2 ms |
2668 KB |
Output is correct |
13 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
14 |
Correct |
2 ms |
2668 KB |
Output is correct |
15 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
16 |
Correct |
2 ms |
2668 KB |
Output is correct |
17 |
Partially correct |
2 ms |
2688 KB |
Partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
2 |
Partially correct |
2 ms |
2796 KB |
Partially correct |
3 |
Partially correct |
2 ms |
2796 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 |
Correct |
3 ms |
2796 KB |
Output is 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 |
Correct |
2 ms |
2796 KB |
Output is correct |
13 |
Correct |
2 ms |
2796 KB |
Output is correct |
14 |
Correct |
3 ms |
2796 KB |
Output is correct |
15 |
Correct |
2 ms |
2796 KB |
Output is correct |
16 |
Partially correct |
3 ms |
2796 KB |
Partially correct |
17 |
Partially correct |
3 ms |
2796 KB |
Partially correct |
18 |
Partially correct |
3 ms |
2796 KB |
Partially correct |
19 |
Correct |
3 ms |
2816 KB |
Output is correct |
20 |
Partially correct |
2 ms |
2796 KB |
Partially correct |
21 |
Correct |
2 ms |
2796 KB |
Output is correct |
22 |
Partially correct |
3 ms |
2796 KB |
Partially correct |
23 |
Partially correct |
3 ms |
2796 KB |
Partially correct |
24 |
Partially correct |
2 ms |
2796 KB |
Partially correct |
25 |
Partially correct |
2 ms |
2796 KB |
Partially correct |
26 |
Partially correct |
3 ms |
2796 KB |
Partially correct |
27 |
Partially correct |
2 ms |
2796 KB |
Partially correct |
28 |
Correct |
3 ms |
2796 KB |
Output is correct |
29 |
Correct |
2 ms |
2796 KB |
Output is correct |
30 |
Correct |
3 ms |
2796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2668 KB |
Output is correct |
2 |
Correct |
2 ms |
2668 KB |
Output is correct |
3 |
Correct |
2 ms |
2668 KB |
Output is correct |
4 |
Correct |
2 ms |
2668 KB |
Output is correct |
5 |
Correct |
2 ms |
2668 KB |
Output is correct |
6 |
Correct |
2 ms |
2668 KB |
Output is correct |
7 |
Correct |
2 ms |
2668 KB |
Output is correct |
8 |
Correct |
2 ms |
2668 KB |
Output is correct |
9 |
Correct |
2 ms |
2668 KB |
Output is correct |
10 |
Correct |
2 ms |
2668 KB |
Output is correct |
11 |
Correct |
2 ms |
2668 KB |
Output is correct |
12 |
Correct |
2 ms |
2668 KB |
Output is correct |
13 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
14 |
Correct |
2 ms |
2668 KB |
Output is correct |
15 |
Partially correct |
2 ms |
2668 KB |
Partially correct |
16 |
Correct |
2 ms |
2668 KB |
Output is correct |
17 |
Partially correct |
2 ms |
2688 KB |
Partially correct |
18 |
Partially correct |
2 ms |
2668 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 |
3 ms |
2796 KB |
Partially correct |
23 |
Partially correct |
3 ms |
2796 KB |
Partially correct |
24 |
Correct |
3 ms |
2796 KB |
Output is 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 |
Correct |
2 ms |
2796 KB |
Output is correct |
30 |
Correct |
2 ms |
2796 KB |
Output is correct |
31 |
Correct |
3 ms |
2796 KB |
Output is correct |
32 |
Correct |
2 ms |
2796 KB |
Output is correct |
33 |
Partially correct |
3 ms |
2796 KB |
Partially correct |
34 |
Partially correct |
3 ms |
2796 KB |
Partially correct |
35 |
Partially correct |
3 ms |
2796 KB |
Partially correct |
36 |
Correct |
3 ms |
2816 KB |
Output is correct |
37 |
Partially correct |
2 ms |
2796 KB |
Partially correct |
38 |
Correct |
2 ms |
2796 KB |
Output is correct |
39 |
Partially correct |
3 ms |
2796 KB |
Partially correct |
40 |
Partially correct |
3 ms |
2796 KB |
Partially correct |
41 |
Partially correct |
2 ms |
2796 KB |
Partially correct |
42 |
Partially correct |
2 ms |
2796 KB |
Partially correct |
43 |
Partially correct |
3 ms |
2796 KB |
Partially correct |
44 |
Partially correct |
2 ms |
2796 KB |
Partially correct |
45 |
Correct |
3 ms |
2796 KB |
Output is correct |
46 |
Correct |
2 ms |
2796 KB |
Output is correct |
47 |
Correct |
3 ms |
2796 KB |
Output is correct |
48 |
Partially correct |
106 ms |
12140 KB |
Partially correct |
49 |
Partially correct |
120 ms |
13164 KB |
Partially correct |
50 |
Partially correct |
133 ms |
13164 KB |
Partially correct |
51 |
Partially correct |
84 ms |
10912 KB |
Partially correct |
52 |
Partially correct |
117 ms |
13036 KB |
Partially correct |
53 |
Partially correct |
100 ms |
12012 KB |
Partially correct |
54 |
Correct |
59 ms |
11884 KB |
Output is correct |
55 |
Correct |
167 ms |
21612 KB |
Output is correct |
56 |
Partially correct |
145 ms |
17612 KB |
Partially correct |
57 |
Partially correct |
141 ms |
16000 KB |
Partially correct |
58 |
Partially correct |
135 ms |
14572 KB |
Partially correct |
59 |
Partially correct |
140 ms |
13292 KB |
Partially correct |
60 |
Correct |
83 ms |
12596 KB |
Output is correct |
61 |
Correct |
88 ms |
12784 KB |
Output is correct |
62 |
Correct |
101 ms |
13036 KB |
Output is correct |
63 |
Correct |
94 ms |
12396 KB |
Output is correct |
64 |
Partially correct |
111 ms |
13548 KB |
Partially correct |
65 |
Partially correct |
103 ms |
13676 KB |
Partially correct |
66 |
Partially correct |
91 ms |
12652 KB |
Partially correct |
67 |
Correct |
62 ms |
10420 KB |
Output is correct |
68 |
Partially correct |
89 ms |
12012 KB |
Partially correct |
69 |
Correct |
97 ms |
13548 KB |
Output is correct |
70 |
Partially correct |
87 ms |
12908 KB |
Partially correct |
71 |
Partially correct |
61 ms |
10220 KB |
Partially correct |
72 |
Partially correct |
68 ms |
11244 KB |
Partially correct |
73 |
Correct |
97 ms |
13548 KB |
Output is correct |
74 |
Correct |
85 ms |
12652 KB |
Output is correct |
75 |
Partially correct |
126 ms |
12908 KB |
Partially correct |
76 |
Correct |
121 ms |
13036 KB |
Output is correct |
77 |
Correct |
108 ms |
13292 KB |
Output is correct |
78 |
Partially correct |
69 ms |
9836 KB |
Partially correct |
79 |
Correct |
78 ms |
10860 KB |
Output is correct |
80 |
Partially correct |
125 ms |
12908 KB |
Partially correct |
81 |
Partially correct |
101 ms |
13524 KB |
Partially correct |
82 |
Correct |
96 ms |
13292 KB |
Output is correct |