Untitled

mail@pastecode.io avatar
unknown
c_cpp
a year ago
1.0 kB
1
Indexable
Never
#include "bits/stdc++.h"
using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(x...)
#endif

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> v(n);
    for (int &i : v) {
        cin >> i;
        i--;
    }
    vector<int> g[n];
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    int q;
    cin >> q;
    while (q--) {
        int C, V;
        cin >> C >> V;
        C--; V--;
        v[C] = V;
        int ans = 0;
        for (int i = 0; i < n; i++) {
            for (int &u : g[i]) {
                ans += (v[u] != v[i]);
            }
        }
        cout << ans / 2 << '\n';
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    freopen("input.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
    int tests = 1;
    // cin >> tests;
    while (tests--) {
        solve();
    }
    return 0;
}