# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
659669 |
2022-11-18T23:00:11 Z |
zaneyu |
Village (BOI20_village) |
C++14 |
|
172 ms |
36932 KB |
/*input
7
4 2
5 7
3 4
6 3
1 3
4 5
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long int ll;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
#define ld double
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
const ll maxn=2e5+5;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e16;
const int INF=0x3f3f3f3f;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
ll mult(ll a,ll b){
return ((a%MOD)*(b%MOD))%MOD;
}
ll mypow(ll a,ll b){
if(b<=0) return 1;
ll res=1LL;
while(b){
if(b&1) res=mult(res,a);
a=mult(a,a);
b>>=1;
}
return res;
}
set<int> v[maxn];
vector<int> v2[maxn];
int ans[maxn];
int rev[maxn];
int mx[maxn];
vector<int> pre;
ll mxx=0;
int n;
int dfs(int u,int p){
pre.pb(u);
int s=1;
for(int x:v[u]){
if(x!=p){
int z=dfs(x,u);
mxx+=min(z,n-z);
s+=z;
}
}
return s;
}
int32_t main(){
ios::sync_with_stdio(false),cin.tie(0);
queue<int> q;
cin>>n;
REP(i,n-1){
int a,b;
cin>>a>>b;
v[a].insert(b);
v[b].insert(a);
v2[a].pb(b);
v2[b].pb(a);
}
REP1(i,n){
ans[i]=rev[i]=i;
if(sz(v[i])==1) q.push(i);
}
dfs(1,-1);
int cnt=0;
while(!q.empty()){
int z=q.front();
q.pop();
if(!sz(v[z]) and ans[z]==z){
//cout<<z<<'\n';
int x=v2[z][0];
int k=rev[x];
ans[k]=z;
ans[z]=x;
rev[x]=z;
rev[z]=k;
cnt+=2;
}
for(int x:v[z]){
if(ans[z]==z){
int k=rev[x];
ans[k]=z;
ans[z]=x;
rev[x]=z;
rev[z]=k;
cnt+=2;
}
if(v[x].find(z)!=v[x].end()) v[x].erase(z);
//if(v[z].find(x)!=v[z].end()) v[z].erase(x);
if(sz(v[x])==1){
q.push(x);
}
}
v[z].clear();
}
cout<<cnt<<' '<<2*mxx<<'\n';
REP1(i,n) cout<<ans[i]<<' ';
cout<<'\n';
REP(i,sz(pre)){
mx[pre[i]]=pre[(i+n/2)%n];
}
REP1(i,n) cout<<mx[i]<<' ';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14380 KB |
Output is correct |
2 |
Correct |
7 ms |
14420 KB |
Output is correct |
3 |
Correct |
7 ms |
14328 KB |
Output is correct |
4 |
Correct |
8 ms |
14388 KB |
Output is correct |
5 |
Correct |
8 ms |
14420 KB |
Output is correct |
6 |
Correct |
7 ms |
14420 KB |
Output is correct |
7 |
Correct |
7 ms |
14420 KB |
Output is correct |
8 |
Correct |
9 ms |
14420 KB |
Output is correct |
9 |
Correct |
7 ms |
14320 KB |
Output is correct |
10 |
Correct |
7 ms |
14420 KB |
Output is correct |
11 |
Correct |
8 ms |
14348 KB |
Output is correct |
12 |
Correct |
8 ms |
14420 KB |
Output is correct |
13 |
Correct |
7 ms |
14416 KB |
Output is correct |
14 |
Correct |
7 ms |
14416 KB |
Output is correct |
15 |
Correct |
7 ms |
14420 KB |
Output is correct |
16 |
Correct |
7 ms |
14416 KB |
Output is correct |
17 |
Correct |
7 ms |
14372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14420 KB |
Output is correct |
2 |
Correct |
7 ms |
14420 KB |
Output is correct |
3 |
Correct |
8 ms |
14420 KB |
Output is correct |
4 |
Correct |
8 ms |
14552 KB |
Output is correct |
5 |
Correct |
8 ms |
14548 KB |
Output is correct |
6 |
Correct |
10 ms |
14544 KB |
Output is correct |
7 |
Correct |
8 ms |
14548 KB |
Output is correct |
8 |
Correct |
7 ms |
14584 KB |
Output is correct |
9 |
Correct |
8 ms |
14548 KB |
Output is correct |
10 |
Correct |
7 ms |
14548 KB |
Output is correct |
11 |
Correct |
8 ms |
14548 KB |
Output is correct |
12 |
Correct |
9 ms |
14548 KB |
Output is correct |
13 |
Correct |
8 ms |
14544 KB |
Output is correct |
14 |
Correct |
8 ms |
14548 KB |
Output is correct |
15 |
Correct |
7 ms |
14544 KB |
Output is correct |
16 |
Correct |
8 ms |
14560 KB |
Output is correct |
17 |
Correct |
8 ms |
14548 KB |
Output is correct |
18 |
Correct |
8 ms |
14548 KB |
Output is correct |
19 |
Correct |
8 ms |
14588 KB |
Output is correct |
20 |
Correct |
9 ms |
14544 KB |
Output is correct |
21 |
Correct |
8 ms |
14544 KB |
Output is correct |
22 |
Correct |
8 ms |
14548 KB |
Output is correct |
23 |
Correct |
8 ms |
14572 KB |
Output is correct |
24 |
Correct |
8 ms |
14552 KB |
Output is correct |
25 |
Correct |
8 ms |
14424 KB |
Output is correct |
26 |
Correct |
8 ms |
14584 KB |
Output is correct |
27 |
Correct |
8 ms |
14420 KB |
Output is correct |
28 |
Correct |
8 ms |
14548 KB |
Output is correct |
29 |
Correct |
8 ms |
14560 KB |
Output is correct |
30 |
Correct |
7 ms |
14548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14380 KB |
Output is correct |
2 |
Correct |
7 ms |
14420 KB |
Output is correct |
3 |
Correct |
7 ms |
14328 KB |
Output is correct |
4 |
Correct |
8 ms |
14388 KB |
Output is correct |
5 |
Correct |
8 ms |
14420 KB |
Output is correct |
6 |
Correct |
7 ms |
14420 KB |
Output is correct |
7 |
Correct |
7 ms |
14420 KB |
Output is correct |
8 |
Correct |
9 ms |
14420 KB |
Output is correct |
9 |
Correct |
7 ms |
14320 KB |
Output is correct |
10 |
Correct |
7 ms |
14420 KB |
Output is correct |
11 |
Correct |
8 ms |
14348 KB |
Output is correct |
12 |
Correct |
8 ms |
14420 KB |
Output is correct |
13 |
Correct |
7 ms |
14416 KB |
Output is correct |
14 |
Correct |
7 ms |
14416 KB |
Output is correct |
15 |
Correct |
7 ms |
14420 KB |
Output is correct |
16 |
Correct |
7 ms |
14416 KB |
Output is correct |
17 |
Correct |
7 ms |
14372 KB |
Output is correct |
18 |
Correct |
8 ms |
14420 KB |
Output is correct |
19 |
Correct |
7 ms |
14420 KB |
Output is correct |
20 |
Correct |
8 ms |
14420 KB |
Output is correct |
21 |
Correct |
8 ms |
14552 KB |
Output is correct |
22 |
Correct |
8 ms |
14548 KB |
Output is correct |
23 |
Correct |
10 ms |
14544 KB |
Output is correct |
24 |
Correct |
8 ms |
14548 KB |
Output is correct |
25 |
Correct |
7 ms |
14584 KB |
Output is correct |
26 |
Correct |
8 ms |
14548 KB |
Output is correct |
27 |
Correct |
7 ms |
14548 KB |
Output is correct |
28 |
Correct |
8 ms |
14548 KB |
Output is correct |
29 |
Correct |
9 ms |
14548 KB |
Output is correct |
30 |
Correct |
8 ms |
14544 KB |
Output is correct |
31 |
Correct |
8 ms |
14548 KB |
Output is correct |
32 |
Correct |
7 ms |
14544 KB |
Output is correct |
33 |
Correct |
8 ms |
14560 KB |
Output is correct |
34 |
Correct |
8 ms |
14548 KB |
Output is correct |
35 |
Correct |
8 ms |
14548 KB |
Output is correct |
36 |
Correct |
8 ms |
14588 KB |
Output is correct |
37 |
Correct |
9 ms |
14544 KB |
Output is correct |
38 |
Correct |
8 ms |
14544 KB |
Output is correct |
39 |
Correct |
8 ms |
14548 KB |
Output is correct |
40 |
Correct |
8 ms |
14572 KB |
Output is correct |
41 |
Correct |
8 ms |
14552 KB |
Output is correct |
42 |
Correct |
8 ms |
14424 KB |
Output is correct |
43 |
Correct |
8 ms |
14584 KB |
Output is correct |
44 |
Correct |
8 ms |
14420 KB |
Output is correct |
45 |
Correct |
8 ms |
14548 KB |
Output is correct |
46 |
Correct |
8 ms |
14560 KB |
Output is correct |
47 |
Correct |
7 ms |
14548 KB |
Output is correct |
48 |
Correct |
142 ms |
29792 KB |
Output is correct |
49 |
Correct |
161 ms |
31316 KB |
Output is correct |
50 |
Correct |
172 ms |
31304 KB |
Output is correct |
51 |
Correct |
116 ms |
27588 KB |
Output is correct |
52 |
Correct |
158 ms |
31024 KB |
Output is correct |
53 |
Correct |
149 ms |
29372 KB |
Output is correct |
54 |
Correct |
62 ms |
25548 KB |
Output is correct |
55 |
Correct |
142 ms |
36932 KB |
Output is correct |
56 |
Correct |
163 ms |
33896 KB |
Output is correct |
57 |
Correct |
149 ms |
32848 KB |
Output is correct |
58 |
Correct |
153 ms |
32128 KB |
Output is correct |
59 |
Correct |
158 ms |
31368 KB |
Output is correct |
60 |
Correct |
141 ms |
31684 KB |
Output is correct |
61 |
Correct |
152 ms |
31704 KB |
Output is correct |
62 |
Correct |
158 ms |
31944 KB |
Output is correct |
63 |
Correct |
139 ms |
30720 KB |
Output is correct |
64 |
Correct |
162 ms |
31880 KB |
Output is correct |
65 |
Correct |
160 ms |
31852 KB |
Output is correct |
66 |
Correct |
138 ms |
30812 KB |
Output is correct |
67 |
Correct |
107 ms |
27292 KB |
Output is correct |
68 |
Correct |
135 ms |
29276 KB |
Output is correct |
69 |
Correct |
156 ms |
31936 KB |
Output is correct |
70 |
Correct |
135 ms |
30884 KB |
Output is correct |
71 |
Correct |
102 ms |
26568 KB |
Output is correct |
72 |
Correct |
123 ms |
28224 KB |
Output is correct |
73 |
Correct |
156 ms |
31916 KB |
Output is correct |
74 |
Correct |
135 ms |
30404 KB |
Output is correct |
75 |
Correct |
155 ms |
31160 KB |
Output is correct |
76 |
Correct |
160 ms |
31232 KB |
Output is correct |
77 |
Correct |
160 ms |
30744 KB |
Output is correct |
78 |
Correct |
97 ms |
25888 KB |
Output is correct |
79 |
Correct |
118 ms |
27712 KB |
Output is correct |
80 |
Correct |
159 ms |
31172 KB |
Output is correct |
81 |
Correct |
151 ms |
31008 KB |
Output is correct |
82 |
Correct |
149 ms |
31536 KB |
Output is correct |