func_code_string: #include <bits/stdc++.h>   using namespace std;   template <typename T>   ostream &operator<<(ostream &os, const vector<T> &v) {     os <<  { ;     string sep;     for (const auto &x : v) os << sep << x, sep =  ,  ;     return os <<  } ;   }   template <typename T, size_t size>   ostream &operator<<(ostream &os, const array<T, size> &arr) {     os <<  { ;     string sep;     for (const auto &x : arr) os << sep << x, sep =  ,  ;     return os <<  } ;   }   template <typename A, typename B>   ostream &operator<<(ostream &os, const pair<A, B> &p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   void dbg_out() { cerr << endl; }   template <typename Head, typename... Tail>   void dbg_out(Head H, Tail... T) {     cerr <<     << H;     dbg_out(T...);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int N, M;     cin >> N >> M;     vector<int> which_tower(N);     vector<set<int>> towers(M);     int answer = N - 1;     for (int i = 0; i < N; i++) {       cin >> which_tower[i];       which_tower[i]--;       towers[which_tower[i]].insert(i);       if (i > 0 && which_tower[i] == which_tower[i - 1]) answer--;     }     auto &&merge_into = [&](int from, int to) {       if (towers[from].size() > towers[to].size()) swap(towers[from], towers[to]);       for (auto &x : towers[from]) {         answer -= int(towers[to].count(x - 1));         answer -= int(towers[to].count(x + 1));       }       for (auto &x : towers[from]) towers[to].insert(x);       towers[from].clear();     };     cout << answer <<   n ;     for (int q = 0; q < M - 1; q++) {       int a, b;       cin >> a >> b;       a--;       b--;       merge_into(b, a);       cout << answer <<   n ;     }   }   