제출 #771472

#제출 시각아이디문제언어결과실행 시간메모리
771472siewjh다리 (APIO19_bridges)C++17
59 / 100
3056 ms39952 KiB
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; const int MAXN = 50005; const int MAXE = 100005; int par[MAXN], sz[MAXN]; bool ch[MAXN]; vector<pair<int, int>> jst; struct edge{ int a, b, w; }; struct query{ int t, x, w; }; int root(int x){ if (par[x] == -1) return x; else return root(par[x]); } void join(int a, int b){ int ra = root(a), rb = root(b); if (ra == rb) return; if (sz[ra] < sz[rb]) swap(ra, rb); // ra larger par[rb] = ra; sz[ra] += sz[rb]; jst.push_back({ra, rb}); } void rollback(){ while (!jst.empty()){ int ra, rb; tie(ra, rb) = jst.back(); jst.pop_back(); par[rb] = -1; sz[ra] -= sz[rb]; } } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int nodes, edges; cin >> nodes >> edges; vector<edge> elist(edges + 1); for (int i = 1; i <= edges; i++){ int a, b, w; cin >> a >> b >> w; elist[i] = {a, b, w}; } int queries; cin >> queries; vector<query> qlist(queries); for (int i = 0; i < queries; i++){ int typ, ind, w; cin >> typ >> ind >> w; qlist[i] = {typ, ind, w}; } vector<int> ans(queries, -1); const int bsz = 600; vector<int> dyna[bsz]; for (int l = 0; l < queries; l += bsz){ int r = min(l + bsz, queries) - 1; fill(par + 1, par + nodes + 1, -1); fill(sz + 1, sz + nodes + 1, 1); vector<int> qv, stat, chv; for (int i = l; i <= r; i++){ if (qlist[i].t == 1) ch[qlist[i].x] = 1; } for (int i = 1; i <= edges; i++){ if (ch[i]) chv.push_back(i); else stat.push_back(i); } for (int i = l; i <= r; i++){ int x = qlist[i].x, w = qlist[i].w; if (qlist[i].t == 1) elist[x].w = w; else{ qv.push_back(i); dyna[i - l].clear(); for (int eind : chv) if (elist[eind].w >= w) dyna[i - l].push_back(eind); } } sort(stat.begin(), stat.end(), [&](int a, int b){return elist[a].w > elist[b].w;}); sort(qv.begin(), qv.end(), [&](int a, int b){return qlist[a].w > qlist[b].w;}); int stind = 0; for (int qind : qv){ int w = qlist[qind].w, x = qlist[qind].x; while (stind != stat.size() && elist[stat[stind]].w >= w){ int eind = stat[stind]; join(elist[eind].a, elist[eind].b); stind++; } jst.clear(); for (int eind : dyna[qind - l]) join(elist[eind].a, elist[eind].b); ans[qind] = sz[root(x)]; rollback(); } for (int x : chv) ch[x] = 0; } for (int i = 0; i < queries; i++) if (ans[i] != -1) cout << ans[i] << '\n'; return 0; }

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

bridges.cpp: In function 'int main()':
bridges.cpp:81:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |    while (stind != stat.size() && elist[stat[stind]].w >= w){
      |           ~~~~~~^~~~~~~~~~~~~~
#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...