Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long int;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

ll n, a, b;
vector<vector<ll>> g;
vector<ll> e, o, ans;

void dfs(ll at, ll from, ll mod){

	if(mod == 0){
		e.push_back(at);
	}
	else{
		o.push_back(at);
	}
	
	zep(i, 0, g[at].size()){
		if(g[at][i] != from){
			dfs(g[at][i], at, 1-mod);
		}
	}
	return;
}

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	cin >> n;
	g.resize(n);
	zep(i, 0, n-1){
		cin >> a >> b;
		a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	
	dfs(0, -1, 0);
	
	ans.resize(n);
	ll a = e.size();
	ll b = o.size();
	ll x = (n+2)/3;
	ll y = (n+1)/3;
	ll z = n/3;
	if(a <= x+z){
		zep(i, 0, a){
			if(x > 0){
				ans[e[i]] = 3*x-2;
				x--;
			}
			else{
				ans[e[i]] = 3*z;
				z--;
			}
		}
		zep(i, 0, b){
			if(y > 0){
				ans[o[i]] = 3*y-1;
				y--;
			}
			else{
				ans[o[i]] = 3*z;
				z--;
			}
		}
	}
	else{
		if(b <= z){
			zep(i, 0, b){
				ans[o[i]] = 3*z;
				z--;
			}
			zep(i, 0, a){
				if(x > 0){
					ans[e[i]] = 3*x-2;
					x--;
				}
				else{
					if(y > 0){
						ans[e[i]] = 3*y-1;
						y--;
					}
					else{
						ans[e[i]] = 3*z;
						z--;
					}
				}
			}
		}
		else{
			print(-1)
		}
		/*if(b <= x+z){
			zep(i, 0, b){
				if(x > 0){
					ans[o[i]] = 3*x-2;
					x--;
				}
				else{
					ans[o[i]] = 3*z;
					z--;
				}
			}
			zep(i, 0, a){
				if(y > 0){
					ans[e[i]] = 3*y-1;
					y--;
				}
				else{
					ans[e[i]] = 3*z;
					z--;
				}
			}
		}
		else{
			if(a <= z){
				zep(i, 0, a){
					ans[e[i]] = 3*z;
					z--;
				}
				zep(i, 0, b){
					if(x > 0){
						ans[o[i]] = 3*x-2;
						x--;
					}
					else{
						if(y > 0){
							ans[o[i]] = 3*y-1;
							y--;
						}
						else{
							ans[o[i]] = 3*z;
							z--;
						}
					}
				}
			}
			else{
				if(b <= z){
					zep(i, 0, b){
						ans[o[i]] = 3*z;
						z--;
					}
					zep(i, 0, a){
						if(x > 0){
							ans[e[i]] = 3*x-2;
							x--;
						}
						else{
							if(y > 0){
								ans[e[i]] = 3*y-1;
								y--;
							}
							else{
								ans[e[i]] = 3*z;
								z--;
							}
						}
					}
				}
				else{
					print(-1)
				}
			}
		}*/
	}
	zep(i, 0, n){
		cout << ans[i] << " ";
	}
	cout << endl;
	return 0;
}

Compiler output:
a.cc:3:19: error: declaration does not declare anything [-fpermissive]
    3 | typedef long long int;
      |                   ^~~
a.cc:4:14: error: 'll' was not declared in this scope
    4 | typedef pair<ll, ll> P;
      |              ^~
a.cc:4:18: error: 'll' was not declared in this scope
    4 | typedef pair<ll, ll> P;
      |                  ^~
a.cc:4:20: error: template argument 1 is invalid
    4 | typedef pair<ll, ll> P;
      |                    ^
a.cc:4:20: error: template argument 2 is invalid
a.cc:5:7: error: 'll' does not name a type
    5 | const ll MOD = 1e9+7;
      |       ^~
a.cc:6:7: error: 'll' does not name a type
    6 | const ll INF = 1e18;
      |       ^~
a.cc:13:1: error: 'll' does not name a type
   13 | ll n, a, b;
      | ^~
a.cc:14:15: error: 'll' was not declared in this scope
   14 | vector<vector<ll>> g;
      |               ^~
a.cc:14:15: error: template argument 1 is invalid
a.cc:14:15: error: template argument 2 is invalid
a.cc:14:17: error: template argument 1 is invalid
   14 | vector<vector<ll>> g;
      |                 ^~
a.cc:14:17: error: template argument 2 is invalid
a.cc:15:8: error: 'll' was not declared in this scope
   15 | vector<ll> e, o, ans;
      |        ^~
a.cc:15:10: error: template argument 1 is invalid
   15 | vector<ll> e, o, ans;
      |          ^
a.cc:15:10: error: template argument 2 is invalid
a.cc:17:6: error: variable or field 'dfs' declared void
   17 | void dfs(ll at, ll from, ll mod){
      |      ^~~
a.cc:17:10: error: 'll' was not declared in this scope
   17 | void dfs(ll at, ll from, ll mod){
      |          ^~
a.cc:17:17: error: 'll' was not declared in this scope
   17 | void dfs(ll at, ll from, ll mod){
      |                 ^~
a.cc:17:26: error: 'll' was not declared in this scope
   17 | void dfs(ll at, ll from, ll mod){
      |                          ^~
a.cc: In function 'int main()':
a.cc:37:16: error: 'n' was not declared in this scope; did you mean 'yn'?
   37 |         cin >> n;
      |                ^
      |                yn
a.cc:38:11: error: request for member 'resize' in 'g', which is of non-class type 'int'
   38 |         g.resize(n);
      |           ^~~~~~
a.cc:8:24: error: 'll' was not declared in this scope
    8 | #define zep(i,m,n) for(ll i = (m); i < (n); i++)
      |                        ^~
a.cc:39:9: note: in expansion of macro 'zep'
   39 |         zep(i, 0, n-1){
      |         ^~~
a.cc:39:13: error: 'i' was not declared in this scope
   39 |         zep(i, 0, n-1){
      |             ^
a.cc:8:36: note: in definition of macro 'zep'
    8 | #define zep(i,m,n) for(ll i = (m); i < (n); i++)
      |                                    ^
a.cc:40:24: error: 'a' was not declared in this scope
   40 |                 cin >> a >> b;
      |                        ^
a.cc:40:29: error: 'b' was not declared in this scope
   40 |                 cin >> a >> b;
      |                             ^
a.cc:46:9: error: 'dfs' was not declared in this scope; did you mean 'ffs'?
   46 |         dfs(0, -1, 0);
      |         ^~~
      |         ffs
a.cc:48:13: error: request for member 'resize' in 'ans', which is of non-class type 'int'
   48 |         ans.resize(n);
      |             ^~~~~~
a.cc:49:9: error: 'll' was not declared in this scope
   49 |         ll a = e.size();
      |         ^~
a.cc:50:11: error: expected ';' before 'b'
   50 |         ll b = o.size();
      |           ^~
      |           ;
a.cc:51:11: error: expected ';' before 'x'
   51 |         ll x = (n+2)/3;
      |           ^~
      |           ;
a.cc:52:11: error: expected ';' before 'y'
   52 |         ll y = (n+1)/3;
      |           ^~
      |           ;
a.cc:53:11: error: expected ';' before 'z'
   53 |         ll z = n/3;
      |           ^~
      |           ;
a.cc:54:12: error: 'a' was not declared in this scope
   54 |         if(a <= x+z){
      |            ^
a.cc:54:17: error: 'x' was not declared in this scope
   54 |         if(a <= x+z){
      |                 ^
a.cc:54:19: error: 'z' was not declared in this scope
   54 |         if(a <= x+z){
      |                   ^
a.cc:55:21: error: expected ';' before 'i'
   55 |                 zep(i, 0, a){
      |                     ^
a.cc:8:27: note: in definition of macro 'zep'
    8 | #define zep(i,m,n) for(ll i = (m); i < (n); i++)
      |                           ^
a.cc:55:21: error: 'i' was not declared in this scope
   55 |                 zep(i, 0, a){
      |                     ^
a.cc:8:36: note: in definition of macro 'zep'
    8 | #define zep(i,m,n) for(ll i = (m); i < (n); i++)
      |                                    ^
a.cc:65:21: error: expected ';' before 'i'
   65 |                 zep(i, 0, b){
      |                     ^
a.cc:8:27: note: in definition of macro 'zep'
    8 | #define zep(i,m,n) for(ll i = (m); i < (n); i++)
      |                           ^
a.cc:65:21: error: 'i' was not declared in this scope
   65 |                 zep(i, 0, b){
      |                     ^
a.cc:8:36: note: in definition of macro 'zep'
    8 | #define zep(i,m,n) for(ll i = (m); i < (n); i++)
      |                                    ^
a.cc:65:27: error: 'b' was not declared in this scope
   65 |                 zep(i, 0, b){
      |                           ^
a.cc:8:41: note: in definition of macro 'zep'
    8 | #define zep(i,m,n) for(ll i = (m); i < (n); i++)
      |                                         ^
a.cc:66:28: error: 'y' was not declared in this scope; did you mean 'yn'?
   66 |                         if(y > 0){
      |                            ^
      |                            yn
a.cc:77:20: error: 'b' was not declared in this scope
   77 |                 if(b <= z){
      |                    ^
a.cc:78:29: error: expected ';' before 'i'
   78 |                         zep(i, 0, b){
      |                             ^
a.cc:8:27: note: in definition of macro 'zep'
    8 | #define zep(i,m,n) for(ll i = (m); i < (n); i++)
      |                           ^
a.cc:78:29: error: 'i' was not declared in this scope
   78 |                         zep(i, 0, b){
      |                             ^
a.cc:8:36: note: in definition of macro 'zep'
    8 | #define zep(i,m,n) for(ll i = (m); i < (n); i++)
      |                                    ^
a.cc:82:29: error: expected ';' before 'i'
   82 |                         zep(i, 0, a){
      |                             ^
a.cc:8:27: note: in definition of macro 'zep'
    8 | #define zep(i,m,n) for(ll i = (m); i < (n); i++)
      |                           ^
a.cc:82:29: error: 'i' was not declared in this scope
   82 |                         zep(i, 0, a){
      |                             ^
a.cc:8:36: note: in definition of macro 'zep'
    8 | #define zep(i,m,n) for(ll i = (m); i < (n); i++)
      |                                    ^
a.cc:88:44: error: 'y' was not declared in this scope; did you mean 'yn'?
   88 |                                         if(y > 0){
      |                                            ^
      |                                            yn
a.cc:176:13: error: expected ';' before 'i'
  176 |         zep(i, 0, n){
      |             ^
a.cc:8:27: note: in definition of macro 'zep'
    8 | #define zep(i,m,n) for(ll i = (m); i < (n); i++)
      |                           ^
a.cc:176:13: error: 'i' was not declared in this scope
  176 |         zep(i, 0, n){
      |             ^
a.cc:8:36: note: in definition of macro 'zep'
    8 | #define zep(i,m,n) for(ll i = (m); i < (n); i++)
      |                                    ^