Language: C++


int main()
{
    int n;
    cin >> n;
    vector<int> a(n, 0), b(n, 0);
    vector<int> rank(n, -1);
    rank[0] = 0;
    vector<int> dege = {1};
    for (int i = 0; i < n-1; i++) {
        cin >> a[i] >> b[i];
        int r = rank[a[i] - 1] + 1;
        if (r < 0) {
            while (true) {
                cout << "miss";
            }
        }
        rank[b[i] - 1] = r;
        if (dege.size() > r) {
            dege[r] += 1;
        }
        else {
            dege.push_back(1);
        }
    }

    int degeOdd = 0,degeEven = 0;
    for (int i = 0; i < dege.size(); i++) {
        if (i % 2 == 0) {
            degeEven += dege[i];
        }
        else {
            degeOdd += dege[i];
        }
    }

    vector<int> p(n,0);
    int cntF = 0;
    int cntL = n-1;
    if (degeOdd < n/3) {
        vector<int> zaiko = {}; //前に3の倍数が、その後ろに3n+1の集まりが、その後ろに3n+2の集まりが続く。
        for (int i = 3; i <= n; i = i + 3) {
            zaiko.push_back(i);
        }
        for (int i = 1; i <= n; i = i + 3) {
            zaiko.push_back(i);
        }
        for (int i = 2; i <= n; i = i + 3) {
            zaiko.push_back(i);
        }
        // rankがOddは3の倍数をつけて、rankがEvenは任意につける。
        for (int i = 0; i < n; i++) {
            if (rank[i] % 2 != 0) {
                // rankがOdd→p_iは3の倍数
                p[i] = zaiko[cntF];
                cntF++;
            }
            else {
                p[i] = zaiko[cntL];
                cntL--;
            }
        }
    } else if (degeEven < n / 3) {
        vector<int> zaiko = {}; //前に3の倍数が、その後ろに3n+1の集まりが、その後ろに3n+2の集まりが続く。
        for (int i = 3; i <= n; i = i + 3) {
            zaiko.push_back(i);
        }
        for (int i = 1; i <= n; i = i + 3) {
            zaiko.push_back(i);
        }
        for (int i = 2; i <= n; i = i + 3) {
            zaiko.push_back(i);
        }
        // rankがEvenは3の倍数をつけて、rankがOddは任意につける。
        for (int i = 0; i < n; i++) {
            if (rank[i] % 2 == 0) {
                // rankがEven→p_iは3の倍数
                p[i] = zaiko[cntF];
                cntF++;
            }
            else {
                p[i] = zaiko[cntL];
                cntL--;
            }
        }
    }
    else {
        vector<int> zaiko = {}; //前に3n+1の集まりが、その後ろに3nの集まりが、その後ろに3n+2の集まりが続く。
        for (int i = 3; i <= n; i = i + 3) {
            zaiko.push_back(i);
        }
        for (int i = 1; i <= n; i = i + 3) {
            zaiko.push_back(i);
        }
        for (int i = 2; i <= n; i = i + 3) {
            zaiko.push_back(i);
        }
        // rankがOddは前から番号をつけて、rankがOddは後ろからつける。
        for (int i = 0; i < n; i++) {
            if (rank[i] % 2 == 0) {
                p[i] = zaiko[cntF];
                cntF++;
            }
            else {
                p[i] = zaiko[cntL];
                cntL--;
            }
        }
    }
    for (int i = 0; i < n - 1; i++) {
        cout << p[i] << " ";
    }
    cout << p[n - 1] << endl;

    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:5:5: error: 'cin' was not declared in this scope
    5 |     cin >> n;
      |     ^~~
a.cc:6:5: error: 'vector' was not declared in this scope
    6 |     vector<int> a(n, 0), b(n, 0);
      |     ^~~~~~
a.cc:6:12: error: expected primary-expression before 'int'
    6 |     vector<int> a(n, 0), b(n, 0);
      |            ^~~
a.cc:7:12: error: expected primary-expression before 'int'
    7 |     vector<int> rank(n, -1);
      |            ^~~
a.cc:8:5: error: 'rank' was not declared in this scope
    8 |     rank[0] = 0;
      |     ^~~~
a.cc:9:12: error: expected primary-expression before 'int'
    9 |     vector<int> dege = {1};
      |            ^~~
a.cc:11:16: error: 'a' was not declared in this scope
   11 |         cin >> a[i] >> b[i];
      |                ^
a.cc:11:24: error: 'b' was not declared in this scope
   11 |         cin >> a[i] >> b[i];
      |                        ^
a.cc:15:17: error: 'cout' was not declared in this scope
   15 |                 cout << "miss";
      |                 ^~~~
a.cc:19:13: error: 'dege' was not declared in this scope
   19 |         if (dege.size() > r) {
      |             ^~~~
a.cc:28:25: error: 'dege' was not declared in this scope; did you mean 'degeOdd'?
   28 |     for (int i = 0; i < dege.size(); i++) {
      |                         ^~~~
      |                         degeOdd
a.cc:37:12: error: expected primary-expression before 'int'
   37 |     vector<int> p(n,0);
      |            ^~~
a.cc:41:16: error: expected primary-expression before 'int'
   41 |         vector<int> zaiko = {}; //前に3の倍数が、その後ろに3n+1の集まりが、その後ろに3n+2の集まりが続く。
      |                ^~~
a.cc:43:13: error: 'zaiko' was not declared in this scope
   43 |             zaiko.push_back(i);
      |             ^~~~~
a.cc:46:13: error: 'zaiko' was not declared in this scope
   46 |             zaiko.push_back(i);
      |             ^~~~~
a.cc:49:13: error: 'zaiko' was not declared in this scope
   49 |             zaiko.push_back(i);
      |             ^~~~~
a.cc:55:17: error: 'p' was not declared in this scope
   55 |                 p[i] = zaiko[cntF];
      |                 ^
a.cc:55:24: error: 'zaiko' was not declared in this scope
   55 |                 p[i] = zaiko[cntF];
      |                        ^~~~~
a.cc:59:17: error: 'p' was not declared in this scope
   59 |                 p[i] = zaiko[cntL];
      |                 ^
a.cc:59:24: error: 'zaiko' was not declared in this scope
   59 |                 p[i] = zaiko[cntL];
      |                        ^~~~~
a.cc:64:16: error: expected primary-expression before 'int'
   64 |         vector<int> zaiko = {}; //前に3の倍数が、その後ろに3n+1の集まりが、その後ろに3n+2の集まりが続く。
      |                ^~~
a.cc:66:13: error: 'zaiko' was not declared in this scope
   66 |             zaiko.push_back(i);
      |             ^~~~~
a.cc:69:13: error: 'zaiko' was not declared in this scope
   69 |             zaiko.push_back(i);
      |             ^~~~~
a.cc:72:13: error: 'zaiko' was not declared in this scope
   72 |             zaiko.push_back(i);
      |             ^~~~~
a.cc:78:17: error: 'p' was not declared in this scope
   78 |                 p[i] = zaiko[cntF];
      |                 ^
a.cc:78:24: error: 'zaiko' was not declared in this scope
   78 |                 p[i] = zaiko[cntF];
      |                        ^~~~~
a.cc:82:17: error: 'p' was not declared in this scope
   82 |                 p[i] = zaiko[cntL];
      |                 ^
a.cc:82:24: error: 'zaiko' was not declared in this scope
   82 |                 p[i] = zaiko[cntL];
      |                        ^~~~~
a.cc:88:16: error: expected primary-expression before 'int'
   88 |         vector<int> zaiko = {}; //前に3n+1の集まりが、その後ろに3nの集まりが、その後ろに3n+2の集まりが続く。
      |                ^~~
a.cc:90:13: error: 'zaiko' was not declared in this scope
   90 |             zaiko.push_back(i);
      |             ^~~~~
a.cc:93:13: error: 'zaiko' was not declared in this scope
   93 |             zaiko.push_back(i);
      |             ^~~~~
a.cc:96:13: error: 'zaiko' was not declared in this scope
   96 |             zaiko.push_back(i);
      |             ^~~~~
a.cc:101:17: error: 'p' was not declared in this scope
  101 |                 p[i] = zaiko[cntF];
      |                 ^
a.cc:101:24: error: 'zaiko' was not declared in this scope
  101 |                 p[i] = zaiko[cntF];
      |                        ^~~~~
a.cc:105:17: error: 'p' was not declared in this scope
  105 |                 p[i] = zaiko[cntL];
      |                 ^
a.cc:105:24: error: 'zaiko' was not declared in this scope
  105 |                 p[i] = zaiko[cntL];
      |                        ^~~~~
a.cc:111:9: error: 'cout' was not declared in this scope
  111 |         cout << p[i] << " ";
      |         ^~~~
a.cc:111:17: error: 'p' was not declared in this scope
  111 |         cout << p[i] << " ";
      |                 ^
a.cc:113:5: error: 'cout' was not declared in this scope
  113 |     cout << p[n - 1] << endl;
      |     ^~~~
a.cc:113:13: error: 'p' was not declared in this scope
  113 |     cout << p[n - 1] << endl;
      |             ^
a.cc:113:25: error: 'endl' was not declared in this scope
  113 |     cout << p[n - 1] << endl;
      |                         ^~~~