이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int batch = 1001;
int N, M, Q;
int S[100001], P[100001], ans[100001];
int U[100001], V[100001], W[100001];
int T[100001], X[100001], Y[100001];
bool changed[100001]; stack<int> st;
vector<int> join[batch];
void reset() {
for(int l = 1; l <= N; l++)
P[l] = l, S[l] = 1;
}
int findSet(int v) {
if(P[v] == v) return v;
return P[v] = findSet(P[v]);
}
void unionSet(int u, int v) {
u = findSet(u), v = findSet(v);
if(u == v) return;
if(S[u] > S[v]) swap(u, v);
st.push(u); S[v] += S[u];
P[u] = v;
}
void restore(int v) {
while(st.size() > v) {
int K = st.top(); st.pop();
S[P[K]] -= S[K]; P[K] = K;
}
}
bool compare(int u, int v) {
return Y[u] > Y[v];
}
bool compare2(int u, int v) {
return W[u] > W[v];
}
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> N >> M;
for(int l = 1; l <= M; l++)
cin >> U[l] >> V[l] >> W[l];
cin >> Q;
for(int l = 1; l <= Q; l++)
cin >> T[l] >> X[l] >> Y[l];
for(int l = 1; l <= Q; l += batch) {
int r = min(Q, l + batch - 1); reset();
for(int i = 1; i <= M; i++) changed[i] = 0;
vector<int> ask, upd, E;
for(int i = l; i <= r; i++) {
if(T[i] == 1) {
changed[X[i]] = 1;
upd.push_back(i);
}
if(T[i] == 2) ask.push_back(i);
}
for(int i = 1; i <= M; i++)
if(!changed[i]) E.push_back(i);
for(int i = l; i <= r; i++) {
if(T[i] == 1) W[X[i]] = Y[i];
else {
join[i - l].clear();
for(auto j : upd) {
if(W[X[j]] >= Y[i]) join[i - l].push_back(X[j]);
}
}
}
sort(ask.begin(), ask.end(), compare);
sort(E.begin(), E.end(), compare2);
int cur = 0;
for(auto i : ask) {
while(cur < E.size() && W[E[cur]] >= Y[i]) {
unionSet(U[E[cur]], V[E[cur]]); cur++;
}
int prev = st.size();
for(auto j : join[i - l]) unionSet(U[j], V[j]);
ans[i] = S[findSet(X[i])];
restore(prev);
}
}
for(int l = 1; l <= Q; l++) {
if(T[l] == 1) continue;
cout << ans[l] << "\n";
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
bridges.cpp: In function 'void restore(int)':
bridges.cpp:31:33: warning: comparison of integer expressions of different signedness: 'std::stack<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
31 | while(st.size() > v) {
| ~~~~~~~~~~^~~
bridges.cpp: In function 'int32_t main()':
bridges.cpp:77:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
77 | while(cur < E.size() && W[E[cur]] >= Y[i]) {
| ~~~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |