Submission #863438

# Submission time Handle Problem Language Result Execution time Memory
863438 2023-10-20T11:13:31 Z vjudge1 Tree Rotations (POI11_rot) C++17
0 / 100
42 ms 16332 KB
//gm  --- akezhon
#include <bits/stdc++.h>
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #define int long long
#define pb push_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define tm (tl+tr)/2
#define TL v+v, tl, tm
#define TR v+v+1, tm+1, tr
#define DA l <= tl && tr <= r
#define NET r < tl || tr < l
#define double long double
using namespace std;
const int N=2e5+7;
const int M=1e9+7;
const int inf=1e9;
int c[N], tin[N], tout[N], eul[N], sz[N], ans[N], big[N];
vector <pair<int*, int>> rb;
vector <int> g[N];
int n, timer, cnt;
int ok[N];
void dfs(int v=1, int p=0){
	tin[v] = ++timer;
	eul[timer] = v;
	sz[v] = 1;
	for(int to : g[v]){
		if(to == p)continue;
		dfs(to, v);
		sz[v] += sz[to];
		if(sz[to] > sz[big[v]])big[v] = to;
	}
	tout[v] = timer;
}
void roll(int &x){
	rb.push_back({&x, x});
}
void upd(int v){
	if(!ok[c[v]]){
		roll(ok[c[v]]);
		roll(cnt);
		cnt++;
		ok[c[v]] = 1;
	}
}
void go(int v=1, int p=0, int cl=0){
	int temp = rb.size();
	for(int to: g[v]){
		if(to != p && to != big[v])go(to, v, 1);
	}

	if(big[v])go(big[v], v, 0);
	upd(v);
	for(int to: g[v]){
		if(to == p || to == big[v])continue;
		for(int i = tin[to]; i <= tout[to]; i++)upd(eul[i]);
	}
	ans[v] = cnt;
	if(cl){
		while(rb.size()>temp){
			*(rb.back().F) = rb.back().S;
			rb.pop_back();
		}
	}
}
void AlemAmenov(){
	
	cin >> n;
	for(int i=1; i <= n; i++){
		cin >> c[i];
	}
	for(int i=1; i < n; i++){
		int a, b;
		cin >> a >> b;
		g[a].pb(b);
		g[b].pb(a);
	}
	dfs();
	go();
	for(int i=1; i <= n; i++){
		cout << ans[i] << ' ';
	}
}
signed main(){

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
//	freopen("justforfood.in", "r", stdin);
//	freopen("justforfood.out", "w", stdout);
	int RealName=1;
	// cin >> RealName;
//	int C=0;
	while(RealName--){
//		cout << "Case " << ++C << ":\n";
		AlemAmenov();
	}

return 0;
}

Compilation message

rot.cpp: In function 'void go(int, int, int)':
rot.cpp:63:18: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int*, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   63 |   while(rb.size()>temp){
      |         ~~~~~~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 10584 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 10588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 10584 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 10840 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 10844 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 11936 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 13128 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 25 ms 13820 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 39 ms 15572 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 39 ms 16076 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 42 ms 16332 KB Output isn't correct
2 Halted 0 ms 0 KB -