func_code_string: #include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     vector<int> arr(n);     for (auto& x : arr) cin >> x;     vector<int> p(m);     for (int i = 0; i < m; i++) p[i] = i;     vector<vector<int>> mp(m);     int ans = 0;     for (int i = 0; i < n; i++) {       if (i > 0 && arr[i - 1] != arr[i]) ans++;       mp[arr[i] - 1].push_back(i);     }     cout << ans << endl;     for (int i = 0; i < m - 1; i++) {       int u, v;       cin >> u >> v;       u--, v--;       while (p[u] != u) {         u = p[u];       }       while (p[v] != v) {         v = p[v];       }       if (mp[v].size() > mp[u].size()) swap(u, v);       for (int x : mp[v]) {         if (x + 1 < n && arr[x + 1] == u + 1) ans--;         if (x > 0 && arr[x - 1] == u + 1) ans--;       }       for (int x : mp[v]) {         arr[x] = u + 1;         mp[u].push_back(x);       }       mp[v].clear();       p[v] = u;       cout << ans << endl;     }     return 0;   }   