제출 #1268960

#제출 시각아이디문제언어결과실행 시간메모리
1268960hoa208다리 (APIO19_bridges)C++20
0 / 100
2997 ms10336 KiB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define FORD(i, b, a) for (int i = (b), _a = (a); i >= _a; i--)
#define pa pair<ll, ll>
#define fi first
#define se second
#define bit(mask, j) ((mask >> j) & 1)
const   ll mod = 1e9 + 7;
const   ll INF = 1e18;
//--------------------------------------------------------------------
const ll N = 5e4 + 10;
const int BLOCK = 300;
const ll M = 1e5 + 10;
ll p[N], sz[N];
vector<ll> edges;
ll findset(ll u)
{
    return u == p[u] ? u : u = findset(p[u]);
}
void ghep(ll u, ll v)
{
    u = findset(u);
    v = findset(v);
    if(u == v) return;
    if(sz[u] < sz[v]) {
        swap(u, v);
    }
    edges.push_back(v);
    p[v] = u;
    sz[u] += sz[v];
}
void rollback() {
    ll v = edges.back();
    sz[p[v]] -= sz[v];
    p[v] = v;
    edges.pop_back();
}
ll n, m, q;
struct ED {
    ll u, v, d;
} ed[M];
struct QR {
    ll t, x, y;
} qr[M];
ll dx[M], a[N];
struct B {
    ll u, v, d, id;
    bool operator < (const B & a) const {
        return d > a.d || d == a.d && id < a.id;
    }
} b[N * BLOCK];
ll ans[N];
void hbmt() {
    cin >> n >> m;
    FOR(i, 1, m) {
        ll u, v, d;
        cin >> u >> v >> d;
        ed[i] = {u, v, d};
    }
    FOR(i, 1, n) {
        p[i] = i;
        sz[i] = 1;
    }
    cin >> q;
    FOR(i, 1, q) {
        ll t, x, y;
        cin >> t >> x >> y;
        qr[i] = {t, x, y};
        if(i % BLOCK == 0 || i == q) {
            ll pre = (i - BLOCK);
            pre = max(0LL, pre);
            ll o = 0, k = 0;
            FOR(j, pre + 1, i) {
                if(qr[j].t == 1) {
                    a[++k] = j;
                    dx[qr[j].x] = 1; 
                }
                else {
                    b[++o] = {qr[j].x, 0, qr[j].y, j};
                }
            }
            FOR(j, 1, m) {
                if(dx[j]) {
                    dx[j] = 0;
                    continue;
                }
                b[++o] = {ed[j].u, ed[j].v, ed[j].d, -1};
            }
            sort(b + 1, b + o + 1);
            // cout << edges.size() << '\n';
            FOR(j, 1, o) {
                // cout << b[j].u << ' '<< b[j].v << ' '<< b[j].d << ' ' << b[j].id << ' ' << k<< '\n';
                if(b[j].id == -1) {
                    ghep(b[j].u, b[j].v);
                    // cout << edges.size() << '\n';
                }
                else {
                    ll pre_edges_sz = edges.size();
                    FOR(v, 1, k) {
                        if(a[v] <= b[j].id) {
                            if(qr[a[v]].y >= b[j].d) {
                                ll x = qr[a[v]].x;
                                ghep(ed[x].u, ed[x].v);
                            }
                        }
                        else {
                            if(ed[qr[a[v]].x].d >= b[j].d) {
                                ll x = qr[a[v]].x;
                                ghep(ed[x].u, ed[x].v);
                            }
                        }
                    }
                    ans[b[j].id] = sz[findset(b[j].u)];
                    while(edges.size() > pre_edges_sz) rollback();
                }
            }
            while(edges.size() > 0) rollback();
            FOR(j, pre + 1, i) {
                if(qr[j].t == 1) {
                    ed[qr[j].x].d = qr[j].y;
                }
                else {
                    cout << ans[j] << '\n';
                }
            }
        }
    }
}

int main() {
    
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);

    #define NAME "hbmt"
    if(fopen(NAME".inp", "r")) {
        freopen(NAME".inp", "r", stdin);
        freopen(NAME".out", "w", stdout);
    }
    
    //int t;cin>>t;while(t--)
    hbmt();
    return 0;
}

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

bridges.cpp: In function 'int main()':
bridges.cpp:139:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  139 |         freopen(NAME".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bridges.cpp:140:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  140 |         freopen(NAME".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...