Submission #857974

# Submission time Handle Problem Language Result Execution time Memory
857974 2023-10-07T08:18:32 Z Trisanu_Das Village (BOI20_village) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
vector<ll> adj[100005];
ll posmin[100005], posmax[100005], sz[100005], dec1[100005], dec2[100005], ansmin = 0, ansmax = 0, n, cnt = 0;
vector<bool> vis;
 
void dfs(int u, int p){
	sz[x] = 1;
	for(auto v : adj[x]){
		if(v == p)continue;
		dfs(v, u);
		sz[u] += sz[v];
		if(vis[v]) continue;
		vis[u] = true;
		swap(posmin[u], posmin[v]);
		ansmin += 2;
	}
	if(u) ansmax += min(sz[x], n - sz[x]) * 2;
	else if(!vis[0]){
		swap(posmin[0], posmin[adj[0][0]]);
		ansmin += 2;
	}
}
void findroot(int u, int p){
	for(auto v : adj[u]){
		if(v == p) continue;
		if(sz[i] > (n >> 1)){
			dec1[i] = 0;
			dec2[0] = v;
			findroot(v, x);
		}
	}
}
void encode(int u, int p){
	dec1[cnt] = u;
	dec2[u] = cnt++;
	for(auto v : adj[x]){
		if(v == p) continue;
		encode(v, u);
	}
}
	
int main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	cin >> n;
	iota(posmin.begin(), posmin.end(), 0);
	iota(posmax.begin(), posmax.end(), 0);
	for(int i = 0; i < n-1; ++i){
		int u, v; cin >> u >> v;
		adj[u - 1].push_back(v - 1);
		adj[v - 1].push_back(u - 1);
	}
	dfs(0, 0);
	findroot(0, 0);
	encode(dec1[0], dec1[0]);
	for(int i = 0; i < n; i++) posmax[i] = dec1[(dec2[i] + n / 2)%n];
	cout << ansmin << ' ' << ansmax << '\n';
	for(auto x : posmin) cout << x + 1 << ' ';
	cout << '\n';
	for(auto x : posmax) cout << x + 1 << ' ';
	cout << '\n';
}

Compilation message

Village.cpp: In function 'void dfs(int, int)':
Village.cpp:10:5: error: 'x' was not declared in this scope
   10 |  sz[x] = 1;
      |     ^
Village.cpp: In function 'void findroot(int, int)':
Village.cpp:29:9: error: 'i' was not declared in this scope
   29 |   if(sz[i] > (n >> 1)){
      |         ^
Village.cpp:32:16: error: 'x' was not declared in this scope
   32 |    findroot(v, x);
      |                ^
Village.cpp: In function 'void encode(int, int)':
Village.cpp:39:19: error: 'x' was not declared in this scope
   39 |  for(auto v : adj[x]){
      |                   ^
Village.cpp: In function 'int main()':
Village.cpp:48:14: error: request for member 'begin' in 'posmin', which is of non-class type 'll [100005]' {aka 'long long int [100005]'}
   48 |  iota(posmin.begin(), posmin.end(), 0);
      |              ^~~~~
Village.cpp:48:30: error: request for member 'end' in 'posmin', which is of non-class type 'll [100005]' {aka 'long long int [100005]'}
   48 |  iota(posmin.begin(), posmin.end(), 0);
      |                              ^~~
Village.cpp:49:14: error: request for member 'begin' in 'posmax', which is of non-class type 'll [100005]' {aka 'long long int [100005]'}
   49 |  iota(posmax.begin(), posmax.end(), 0);
      |              ^~~~~
Village.cpp:49:30: error: request for member 'end' in 'posmax', which is of non-class type 'll [100005]' {aka 'long long int [100005]'}
   49 |  iota(posmax.begin(), posmax.end(), 0);
      |                              ^~~