Language: C++

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define per(i, a, b) for(int i = (b) - 1; i >= (a); --i)
#define de(x) cout << #x << " = " << x << endl
#define dd(x) cout << #x << " = " << x << " "
#define endl '\n'
#define pw(x) (1ll<<(x))
#define all(x) x.begin(), x.end()
#define sz(x) (int)x. size()
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef vector<int> vi;

int n;
const int N=2e5+1;
vi e[N];
queue<int>que[3];
int dep[N],ans[N];

void dfs(int p,int pre)
{
    for(auto v:e[p])
    {
        if(v==pre)continue;
        dep[v]=dep[p]+1;
        dfs(v,p);
    }
}

int main()
{
    std::ios::sync_with_stdio(0);
    std::cin.tie(0);

    while(cin>>n)
    {
        rep(i,1,n+1)
        {
            e[i].clear();
            que[i%3].push(i);
        }
        rep(i,1,n)
        {
            int x,y;
            cin>>x>>y;
            e[x].pb(y);
            e[y].pb(x);
        }
        dep[1]=1;
        dfs(1,-1);
        bool f=0;
        rep(i,1,n+1)
        {
            if(dep[i]&1)
            {
                if(!que[1].empty())
                {
                    ans[i]=que[1].front();
                    que[1].pop();
                }
                else if(!que[0].empty())
                {
                    ans[i]=que[0].front();
                    que[0].pop();
                }
                else
                {
                    f=1;
                    break;
                }
            }
            else
            {
                if(!que[2].empty())
                {
                    ans[i]=que[2].front();
                    que[2].pop();
                }
                else if(!que[0].empty())
                {
                    ans[i]=que[0].front();
                    que[0].pop();
                }
                else
                {
                    f=1;
                    break;
                }
            }
        }
        if(f)
        {
            while(!que.empty())que.pop();
            rep(i,1,n+1)que[i%3].push(i);
            f=0;
            rep(i,1,n+1)
            {
                if(dep[i]&1)
                {
                    if(!que[2].empty())
                    {
                        ans[i]=que[2].front();
                        que[2].pop();
                    }
                    else if(!que[0].empty())
                    {
                        ans[i]=que[0].front();
                        que[0].pop();
                    }
                    else
                    {
                        f=1;
                        break;
                    }
                }
                else
                {
                    if(!que[1].empty())
                    {
                        ans[i]=que[1].front();
                        que[1].pop();
                    }
                    else if(!que[0].empty())
                    {
                        ans[i]=que[0].front();
                        que[0].pop();
                    }
                    else
                    {
                        f=1;
                        break;
                    }
                }
            }
        }
        if(f)
        {
            while(!que.empty())que.pop();
            rep(i,1,n+1)que[i%3].push(i);
            f=0;
            rep(i,1,n+1)
            {
                if(dep[i]&1)
                {
                    if(!que[0].empty())
                    {
                        ans[i]=que[0].front();
                        que[0].pop();
                    }
                    else if(!que[2].empty())
                    {
                        ans[i]=que[2].front();
                        que[2].pop();
                    }
                    else
                    {
                        f=1;
                        break;
                    }
                }
                else
                {
                    if(!que[0].empty())
                    {
                        ans[i]=que[0].front();
                        que[0].pop();
                    }
                    else if(!que[1].empty())
                    {
                        ans[i]=que[1].front();
                        que[1].pop();
                    }
                    else
                    {
                        f=1;
                        break;
                    }
                }
            }
        }
        if(f)
        {
            while(!que.empty())que.pop();
            rep(i,1,n+1)que[i%3].push(i);
            f=0;
            rep(i,1,n+1)
            {
                if(dep[i]&1)
                {
                    if(!que[0].empty())
                    {
                        ans[i]=que[0].front();
                        que[0].pop();
                    }
                    else if(!que[1].empty())
                    {
                        ans[i]=que[1].front();
                        que[1].pop();
                    }
                    else
                    {
                        f=1;
                        break;
                    }
                }
                else
                {
                    if(!que[0].empty())
                    {
                        ans[i]=que[0].front();
                        que[0].pop();
                    }
                    else if(!que[2].empty())
                    {
                        ans[i]=que[2].front();
                        que[2].pop();
                    }
                    else
                    {
                        f=1;
                        break;
                    }
                }
            }
        }
        if(f)
        {
            cout<<-1<<endl;
            continue;
        }
        else
        {
            rep(i,1,n)cout<<ans[i]<<" ";
            cout<<ans[n]<<endl;
        }
    }

    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:99:24: error: request for member 'empty' in 'que', which is of non-class type 'std::queue<int> [3]'
   99 |             while(!que.empty())que.pop();
      |                        ^~~~~
a.cc:99:36: error: request for member 'pop' in 'que', which is of non-class type 'std::queue<int> [3]'
   99 |             while(!que.empty())que.pop();
      |                                    ^~~
a.cc:144:24: error: request for member 'empty' in 'que', which is of non-class type 'std::queue<int> [3]'
  144 |             while(!que.empty())que.pop();
      |                        ^~~~~
a.cc:144:36: error: request for member 'pop' in 'que', which is of non-class type 'std::queue<int> [3]'
  144 |             while(!que.empty())que.pop();
      |                                    ^~~
a.cc:189:24: error: request for member 'empty' in 'que', which is of non-class type 'std::queue<int> [3]'
  189 |             while(!que.empty())que.pop();
      |                        ^~~~~
a.cc:189:36: error: request for member 'pop' in 'que', which is of non-class type 'std::queue<int> [3]'
  189 |             while(!que.empty())que.pop();
      |                                    ^~~