Submission #416376

# Submission time Handle Problem Language Result Execution time Memory
416376 2021-06-02T10:40:40 Z model_code Rooted MST (innopolis2021_final_E) C++17
10 / 100
303 ms 9408 KB
#include <bits/stdc++.h>
#define ws weights

using namespace std;

typedef long long ll;


const int N = 3e5 + 10;
const int inf = 1e9 + 20;
const ll infty = (ll) (1e18);

int dsu[N];

int get(int v) {
    if (v == dsu[v]) return v;
    else return dsu[v] = get(dsu[v]);
}

void uni(int u, int v) {
    u = get(u), v = get(v);
    dsu[u] = v;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector <int> a(n + 1);
    for (int i = 1; i <= n; i++) cin >> a[i];
    vector <pair <int, pair <int, int> > > e;
    auto add_edge = [&] (int a, int b, int w) {
        e.push_back({w, {a, b}});
    };
    for (int i = 0; i < m; i++) {
        int w, u, v;
        cin >> u >> v >> w;
        add_edge(u, v, w);
    }
    sort(e.begin(), e.end());
    for (int i = 0; i <= n; i++) {
        dsu[i] = i;
    }
    int ws = 2 * n;
    for (auto c : e) {
        if (c.first == 1) {
            if (get(c.second.first) != get(c.second.second)) {
                uni(c.second.first, c.second.second);
                ws--;
            }
        }
    }
    int q;
    cin >> q;
    vector <int> mp(n + 1);
    for (int i = 1; i <= n; i++) {
        if (a[i] == 1) {
            if (get(i) != get(0)) {
                mp[get(i)]++;
                if (mp[get(i)] == 1) ws--;
            }
        }
    }
    while (q--) {
        int i, w;
        cin >> i >> w;
        bool ch = (a[i] != w);
        a[i] = w;
        if (ch) {
            if (w == 1) {
                if (get(0) != get(i)) {
                    mp[get(i)]++;
                    if (mp[get(i)] == 1) ws--;
                }
            } else {
                if (get(0) != get(i)) {
                    mp[get(i)]--;
                    if (mp[get(i)] == 0) ws++;
                }
            }
        }
        cout << ws << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 302 ms 9408 KB Output is correct
2 Correct 217 ms 7600 KB Output is correct
3 Correct 201 ms 6576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 244 ms 6576 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 150 ms 5912 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 150 ms 5912 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 303 ms 9348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -