제출 #992551

#제출 시각아이디문제언어결과실행 시간메모리
992551Neco_arc다리 (APIO19_bridges)C++17
14 / 100
1122 ms17404 KiB
#include <bits/stdc++.h> //#include <bits/debug.hpp> #define ll long long #define all(x) x.begin(), x.end() #define Neco "Bridges" #define resp(x) sort(all(x)), x.resize(unique(all(x)) - x.begin()) #define getbit(x,i) ((x >> i)&1) #define _left id * 2, l, mid #define _right id * 2 + 1, mid + 1, r #define cntbit(x) __builtin_popcountll(x) #define fi(i, a, b) for(int i = a; i <= b; i++) #define fid(i, a, b) for(int i = a; i >= b; i--) #define maxn (int) 2e5 + 7 using namespace std; const ll mod = 1e9 + 7; //972663749 const ll base = 911382323; const int Sqrt = 372; int n, m, q, DEL; int W[maxn], del[maxn], vis[maxn]; int ans[maxn], E[maxn]; vector<int> edges[maxn]; struct edge { int u, v; } Ed[maxn]; struct dl { int type, x, w; } qr[maxn];; struct DSU { int lab[maxn]; void init() { fi(i, 1, n) lab[i] = -1; } int get_rt(int u) { return lab[u] < 0 ? u : lab[u] = get_rt(lab[u]); } void uni(int u, int v) { int p = get_rt(u), q = get_rt(v); if(p == q) return; if(lab[p] > lab[q]) swap(p, q); lab[p] += lab[q], lab[q] = p; } } Dsu; int dfs(int u, int del) { vis[u] = del; int res = Dsu.lab[u]; for(int v : edges[u]) if(vis[v] != del) { res += dfs(v, del); } return res; } void Add(int i) { int u = Dsu.get_rt(Ed[qr[i].x].u), v = Dsu.get_rt(Ed[qr[i].x].v); edges[u].push_back(v); edges[v].push_back(u); } void clear(int i) { int u = Dsu.get_rt(Ed[qr[i].x].u), v = Dsu.get_rt(Ed[qr[i].x].v); edges[u].clear(); edges[v].clear(); } void solve() { cin >> n >> m; fi(i, 1, m) { int u, v; cin >> u >> v >> W[i]; E[i] = i; Ed[i] = {u, v}; } cin >> q; fi(i, 1, q) cin >> qr[i].type >> qr[i].x >> qr[i].w; sort(E + 1, E + 1 + m, [](int x, int y) { return W[x] > W[y]; }); vector<dl> P; for(int T = 1; T <= (q - 1) / Sqrt + 1; ++T) { int L = (T - 1) * Sqrt + 1, R = min(q, Sqrt * T); fi(i, L, R) { if(qr[i].type == 1) del[qr[i].x] = T; else P.push_back({qr[i].x, qr[i].w, i}); } Dsu.init(); sort(all(P), [](dl x, dl y) { return x.x > y.x; }); int j = 1; for(auto [x, w, id] : P) { ++DEL; while(W[E[j]] >= w) { if(del[E[j]] != T) Dsu.uni(Ed[E[j]].u, Ed[E[j]].v); ++j; } fi(i, L, R) if(qr[i].type == 1) { int val = i < id ? qr[i].w : W[qr[i].x]; if(val >= w) Add(i); } ans[id] = - dfs(Dsu.get_rt(x), DEL); fi(i, L, R) if(qr[i].type == 1) { int val = i < id ? qr[i].w : W[qr[i].x]; if(val >= w) clear(i); } } fi(i, L, R) if(qr[i].type == 1) W[qr[i].x] = qr[i].w; sort(E + 1, E + 1 + m, [](int x, int y) { return W[x] > W[y]; }); P.clear(); } fi(i, 1, q) if(qr[i].type == 2) cout << ans[i] << '\n'; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if(fopen(Neco".inp", "r")) { freopen(Neco".inp", "r", stdin); freopen(Neco".out", "w", stdout); } int nTest = 1; // cin >> nTest; while(nTest--) { solve(); } return 0; }

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

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