func_code_string: #include <bits/stdc++.h>   using namespace std;   void swapCols(int p1, int p2, vector<vector<int> >& matrix) {     for (int i = 0; i < ((int)(matrix).size()); i++)       swap(matrix[i][p1], matrix[i][p2]);   }   void swapRows(int p1, int p2, vector<vector<int> >& matrix) {     for (int i = 0; i < ((int)(matrix[0]).size()); i++)       swap(matrix[p1][i], matrix[p2][i]);   }   int main() {     ios ::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     vector<vector<int> > matrix(n, vector<int>(n, 0));     vector<tuple<int, int, int> > operations;     vector<int> cols(n), rows(n);     for (int i = 0; i < (n - 1); i++) {       int u, v;       cin >> u >> v;       u--;       v--;       matrix[u][v] = 1;       rows[u]++;       cols[v]++;     }     int dim = n - 1;     while (dim != 0) {       for (int i = 0; i <= dim; i++) {         if (cols[i] == 0) {           swap(cols[i], cols[dim]);           swapCols(i, dim, matrix);           if (i + 1 != dim + 1)             operations.push_back(make_tuple(2, i + 1, dim + 1));           break;         }       }       for (int i = 0; i <= dim; i++) {         if (rows[i] != 0) {           swap(rows[i], rows[dim]);           swapRows(i, dim, matrix);           if (i + 1 != dim + 1)             operations.push_back(make_tuple(1, i + 1, dim + 1));           break;         }       }       for (int i = 0; i <= dim; i++) {         if (matrix[dim][i] == 1) cols[i]--;         if (matrix[i][dim] == 1) rows[i]--;       }       dim--;     }     cout << ((int)(operations).size()) <<   n ;     for (tuple<int, int, int> tup : operations)       cout << get<0>(tup) <<     << get<1>(tup) <<     << get<2>(tup) <<   n ;   }   