이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#include <bits/stdc++.h>
using namespace std;
#ifdef WAIMAI
#define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE)
void dout() {cout << '\n';}
template<typename T, typename...U>
void dout(T t, U...u) {cout << t << (sizeof...(u) ? ", " : ""), dout(u...);}
#else
#define debug(...) 7122
#endif
#define ll long long
#define Waimai ios::sync_with_stdio(false), cin.tie(0)
#define FOR(x,a,b) for (int x = a, I = b; x <= I; x++)
#define pb emplace_back
#define F first
#define S second
const int SIZE = 1e5 + 5;
const int K = 1000;
int n, m, q;
int ans[SIZE];
int a[SIZE], b[SIZE], w[SIZE];
int t[SIZE], p[SIZE], x[SIZE];
bool is[SIZE];
vector<int> op[SIZE];
int to[SIZE], sz[SIZE];
vector<int> st;
int dsu(int x) {
while (x != to[x]) x = to[x];
return x;
}
void Merge(int a, int b) {
a = dsu(a), b = dsu(b);
if (a == b) return;
if (sz[a] < sz[b]) swap(a, b);
st.pb(b);
to[b] = a, sz[a] += sz[b];
}
void rollback(int ver) {
while (st.size() > ver) {
int x = st.back();
st.pop_back();
sz[to[x]] -= sz[x];
to[x] = x;
}
}
void solve() {
cin >> n >> m;
FOR (i, 1, m) cin >> a[i] >> b[i] >> w[i];
cin >> q;
FOR (i, 1, q) cin >> t[i] >> p[i] >> x[i];
iota(to + 1, to + n + 1, 1);
fill(sz + 1, sz + n + 1, 1);
for (int l = 1; l <= q; l += K) {
int r = min(l + K - 1, q);
vector<int> v1, v2, que;
FOR (i, l, r) {
if (t[i] == 1) is[p[i]] = 1, v2.pb(p[i]);
else que.pb(i);
}
FOR (i, l, r) {
if (t[i] == 1) w[p[i]] = x[i];
else for (int id : v2) if (w[id] >= x[i]) op[i].pb(id);
}
FOR (i, 1, m) if (!is[i]) v1.pb(i);
sort(v1.begin(), v1.end(), [](int lhs, int rhs) {
return w[lhs] > w[rhs];
});
sort(que.begin(), que.end(), [](int lhs, int rhs) {
return x[lhs] > x[rhs];
});
int rp = 0;
for (int id : que) {
while (rp < v1.size() && w[v1[rp]] >= x[id]) {
Merge(a[v1[rp]], b[v1[rp]]);
rp++;
}
int ver = st.size();
for (int p : op[id]) Merge(a[p], b[p]);
ans[id] = sz[dsu(p[id])];
rollback(ver);
}
rollback(0);
FOR (i, l, r) if (t[i] == 1) is[p[i]] = 0;
}
FOR (i, 1, q) if (ans[i]) cout << ans[i] << '\n';
}
int main() {
Waimai;
solve();
}
컴파일 시 표준 에러 (stderr) 메시지
bridges.cpp: In function 'void rollback(int)':
bridges.cpp:46:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
46 | while (st.size() > ver) {
| ~~~~~~~~~~^~~~~
bridges.cpp: In function 'void solve()':
bridges.cpp:81:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
81 | while (rp < v1.size() && w[v1[rp]] >= x[id]) {
| ~~~^~~~~~~~~~~
# | 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... |