제출 #158127

#제출 시각아이디문제언어결과실행 시간메모리
158127PeppaPig다리 (APIO19_bridges)C++14
0 / 100
3065 ms70224 KiB
#include <bits/stdc++.h> #define pii pair<int, int> #define x first #define y second using namespace std; const int N = 1e5+5; const int B = 320; struct UnionFindDisjointSet { int par[N], sz[N]; stack<int> S; void reset() { iota(par, par+N, 0), fill_n(sz, N, 1); } int find(int x) { return x == par[x] ? x : find(par[x]); } void unite(int a, int b) { a = find(a), b = find(b); if(a == b) return; if(sz[a] > sz[b]) swap(a, b); par[a] = b, sz[b] += sz[a]; S.emplace(a); } void rollback(int x) { while(S.size() > x) { int now = S.top(); S.pop(); sz[par[now]] -= sz[now]; par[now] = now; } } } dsu; int n, m, q, ans[N]; int u[N], v[N], w[N], t[N], x[N], y[N]; bool chk[N]; int main() { scanf("%d %d", &n, &m); for(int i = 1; i <= m; i++) scanf("%d %d %d", u+i, v+i, w+i); scanf("%d", &q); for(int i = 1; i <= q; i++) scanf("%d %d %d", t+i, x+i, y+i); for(int l = 1, r; l <= q; l += B) { r = min(q, l + B - 1); dsu.reset(); memset(chk, 0, sizeof chk); vector<int> upd, ask, E; for(int i = l; i <= r; i++) { if(t[i] == 1) { upd.emplace_back(i); chk[x[i]] = true; } else ask.emplace_back(i); } for(int i = 1; i <= m; i++) if(!chk[i]) E.emplace_back(i); sort(ask.begin(), ask.end(), [&](int a, int b) { return y[a] > y[b]; }); sort(E.begin(), E.end(), [&](int a, int b) { return w[a] > w[b]; }); int ptr = 0; for(int i : ask) { int idx = x[i], cost = y[i]; while(ptr < E.size() && w[E[ptr]] >= cost) dsu.unite(u[E[ptr]], v[E[ptr]]), ++ptr; int tmp = dsu.S.size(); for(int z : upd) { if(z < i && y[z] >= cost) dsu.unite(u[x[z]], v[x[z]]); if(z > i && w[x[z]] >= cost) dsu.unite(u[x[z]], v[x[z]]); } ans[i] = dsu.sz[dsu.find(idx)]; dsu.rollback(tmp); } for(int i : upd) w[x[i]] = y[i]; } for(int i = 1; i <= q; i++) if(t[i] == 2) printf("%d\n", ans[i]); return 0; }

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

bridges.cpp: In member function 'void UnionFindDisjointSet::rollback(int)':
bridges.cpp:29:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while(S.size() > x) {
                        ^
bridges.cpp: In function 'int main()':
bridges.cpp:67:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             while(ptr < E.size() && w[E[ptr]] >= cost)
                   ~~~~^~~~~~~~~~
bridges.cpp:42:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~~
bridges.cpp:43:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i = 1; i <= m; i++) scanf("%d %d %d", u+i, v+i, w+i);
                                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
bridges.cpp:44:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &q);
     ~~~~~^~~~~~~~~~
bridges.cpp:45:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i = 1; i <= q; i++) scanf("%d %d %d", t+i, x+i, y+i);
                                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...