제출 #551274

#제출 시각아이디문제언어결과실행 시간메모리
551274hoanghq2004다리 (APIO19_bridges)C++14
0 / 100
3084 ms11412 KiB
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 1e5 + 10;
const int B = 300;

int n, m, q;
struct edges {
    int u, v, w, i;
    int operator < (const edges& other) const {
        if (w != other.w) return w > other.w;
        return i < other.i;
    }
} e[N];

set <edges> s;
int temp, num;
int par[N], sz[N];
int ans[N];

struct dta {
    int u, par, sz;
} old[N];

int Find(int u) {
    if (u == par[u]) return u;
    if (temp) old[num++] = {u, par[u], sz[u]};
    return par[u] = Find(par[u]);
}

void Union(int u, int v) {
    if ((u = Find(u)) == (v = Find(v))) return;
    if (temp) {
        old[num++] = {u, par[u], sz[u]};
        old[num++] = {v, par[v], sz[v]};
    }
    if (sz[u] < sz[v]) swap(u, v);
    par[v] = u;
    sz[u] += sz[v];
}

void rollback() {
    for (int i = num - 1; i >= 0; --i) {
        int u = old[i].u;
        par[u] = old[i].par;
        sz[u] = old[i].sz;
    }
    num = 0;
}

/*
3 4
1 2 5
2 3 2
3 1 4
2 3 8
2
1 4 1
2 2 5

*/

int cmd[N], x[N], y[N];
int flag[N], cur[N];

int main() {
    ios :: sync_with_stdio(0); cin.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= m; ++i) {
        cin >> e[i].u >> e[i].v >> e[i].w;
        e[i].i = i;
        s.insert(e[i]);
    }
    cin >> q;
    int cnt = 0;
    for (int T = 0; T < q; ++T) {
        cin >> cmd[cnt] >> x[cnt] >> y[cnt];
        ++cnt;
        if (cnt == B || T == q - 1) {
            for (int i = 1; i <= n; ++i) par[i] = i, sz[i] = 1;
            vector <tuple <int, int, int> > ask;
            vector <int> _;
            for (int i = 0; i < cnt; ++i) {
                if (cmd[i] == 1) {
                    flag[x[i]] = 1;
                    _.push_back(x[i]);
                } else {
                    ask.push_back({y[i], x[i], i});
                }
            }
            sort(ask.begin(), ask.end(), greater<>());
            auto iter = s.begin();
            for (auto [w, z, id]: ask) {
                while (1) {
                    if (iter == s.end() || iter -> w < w) break;
                    if (!flag[iter -> i]) Union(iter -> u, iter -> v);
//                    cout << iter -> u << ' ' << iter -> v << ' ' << iter -> w << ' ' << w << '\n';
                    ++iter;
                }
                for (auto i: _) cur[i] = e[i].w;
                temp = 1;
                for (int i = 0; i < id; ++i)
                    if (cmd[i] == 1) cur[x[i]] = y[i];
                for (auto i: _) {
                    if (cur[i] >= w) Union(e[i].u, e[i].v);
                }
                ans[id] = sz[Find(z)];
                temp = 0;
                rollback();
            }
            for (int i = 0; i < cnt; ++i) {
                if (cmd[i] == 1) {
                    s.erase(e[x[i]]);
                    e[x[i]].w = y[i];
                    s.insert(e[x[i]]);
                    flag[x[i]] = 0;
                } else {
                    cout << ans[i] << '\n';
                }
            }
        }
    }
}

컴파일 시 표준 에러 (stderr) 메시지

bridges.cpp: In function 'int main()':
bridges.cpp:102:23: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  102 |             for (auto [w, z, id]: ask) {
      |                       ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...