# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
318752 | BeanZ | 다리 (APIO19_bridges) | C++14 | 3060 ms | 60440 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// I_Love_LPL
#include <bits/stdc++.h>
using namespace std;
#define ll int
#define endl '\n'
const int N = 1e5 + 5;
vector<pair<ll, ll>> rb;
vector<ll> join[N];
ll u[N], v[N], d[N], t[N], a[N], b[N], ch[N], p[N], ans[N];
void rollback(ll u){
while (rb.size() > u){
p[rb.back().first] = rb.back().second;
rb.pop_back();
}
}
ll find_set(ll u){
if (p[u] < 0) return u;
return find_set(p[u]);
}
void dsu(ll u, ll v){
u = find_set(u);
v = find_set(v);
if (u == v) return;
if (p[u] > p[v]) swap(u, v);
rb.push_back({u, p[u]});
rb.push_back({v, p[v]});
p[u] += p[v];
p[v] = u;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
if (fopen("A.inp", "r")){
freopen("test.inp", "r", stdin);
freopen("test.out", "w", stdout);
}
ll n, m;
cin >> n >> m;
for (int i = 1; i <= m; i++){
cin >> u[i] >> v[i] >> d[i];
}
ll q;
cin >> q;
for (int i = 1; i <= q; i++){
cin >> t[i] >> a[i] >> b[i];
}
const int base = 400;
for (int l = 1; l <= q; l += base){
for (int i = 1; i <= n; i++) p[i] = -1;
ll r = min(l + base - 1, q);
for (int i = 1; i <= m; i++) ch[i] = 0;
rb.clear();
vector<ll> memupd, memres, un;
for (int i = l; i <= r; i++){
if (t[i] == 1) memupd.push_back(a[i]);
}
for (int i = l; i <= r; i++){
if (t[i] == 1){
d[a[i]] = b[i];
ch[a[i]] = 1;
} else {
for (auto j : memupd){
if (d[j] >= b[i]){
join[i].push_back(j);
}
}
memres.push_back(i);
}
}
for (int i = 1; i <= m; i++){
if (ch[i] == 0) un.push_back(i);
}
sort(un.begin(), un.end(), [&](ll g, ll h){return d[g] > d[h];});
sort(memres.begin(), memres.end(), [&](ll g, ll h){return b[g] > b[h];});
ll now = 0;
//for (auto j : memres) cout << j << " ";
//cout << endl;
for (auto j : memres){
while (now < un.size() && d[un[now]] >= b[j]){
dsu(u[un[now]], v[un[now]]);
//cout << u[un[now]] << " " << v[un[now]] << " " << now << " " << a[j] << " " << j << endl;
now++;
}
ll tmp = rb.size();
for (auto o : join[j]){
dsu(u[o], v[o]);
}
//cout << b[j] << endl;
//cout << j << endl;
ans[j] = -p[find_set(a[j])];
//cout << j << " " << ans[j] << endl;
rollback(tmp);
}
}
for (int i = 1; i <= q; i++){
if (t[i] == 2) cout << ans[i] << endl;
}
}
/*
3 4
1 2 5
2 3 2
3 1 4
2 3 8
1
2 1 5
*/
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |