This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define sz(x) (int)x.size()
#define ff first
#define ss second
const ll N = 500000;
const ll M = 1e9 + 7;
int T, n, a[N], b[N], c[N], q, s[N], w[N], t[N], d[N], r2[N], ans, vis[N], m, st[N*8], x3;
vector <pair<int,int>> v[N];
void dfs(int x, int y){
vis[x] = 1;
ans++;
for(auto i : v[x]){
if(vis[i.ff] == 0 and i.ss >= y){
dfs(i.ff,y);
}
}
}
int bld(int nd, int l, int r){
if(l == r) return st[nd] = c[l];
int md = (l + r) / 2;
return st[nd] = min(bld(nd*2,l,md), bld(nd*2+1,md+1,r));
}
int upd(int nd, int l, int r, int ind, int vl){
if((r < ind) or (l > ind)) return st[nd];
if(l == r) return st[nd] = vl;
int md = (l + r) / 2;
return st[nd] = min(upd(nd*2,l,md,ind,vl), upd(nd*2+1,md+1,r,ind,vl));
}
int fnd(int nd, int l, int r, int x, int y){
if(l > y or r < x) return st[nd];
if(l >= x and r <= y){
x3 = min(x3,st[nd]);
return st[nd];
}
int md = (l + r) / 2;
return st[nd] = min(fnd(nd*2,l,md,x,y),fnd(nd*2+1,md+1,r,x,y));
}
int main(){
ios::sync_with_stdio(false); cin.tie(0);
cin >> n >> m;
for(int i = 1; i <= m; i++){
cin >> a[i] >> b[i] >> c[i];
}
cin >> q;
for(int i = 1; i <= q; i++){
cin >> t[i];
if(t[i] == 1){
cin >> d[i] >> r2[i];
}
else {
cin >> s[i] >> w[i];
}
}
if(n <= 1000 and m <= 1000 and q <= 10000){
for(int i = 1; i <= q; i++){
if(t[i] == 1){
c[d[i]] = r2[i];
}
else {
for(int j = 1; j <= n; j++){
v[j].clear();
vis[j] = 0;
}
for(int j = 1; j <= m; j++){
v[a[j]].push_back({b[j],c[j]});
v[b[j]].push_back({a[j],c[j]});
}
ans = 0;
dfs(s[i],w[i]);
cout << ans << '\n';
}
}
}
else {
bld(1,1,m);
for(int i = 1; i <= q; i++){
if(t[i] == 1){
upd(1,1,m,d[i],r2[i]);
}
else {
int l1 = s[i], r1 = m, k = 0, an = n;
while(l1 <= r1){
int md = (l1 + r1) / 2;
x3 = 1e9;
fnd(1,1,m,s[i],md);
if(x3 < w[i]){
r1 = md-1;
k = md;
}
else {
l1 = md+1;
}
}
if(k != 0) an -= (n-k);
int x2 = fnd(1,1,m,1,1);
l1 = 1, r1 = s[i]-1, k = 0;
while(l1 <= r1){
int md = (l1 + r1) / 2;
x3 = 1e9;
fnd(1,1,m,md,s[i]-1);
if(x3 < w[i]){
l1 = md+1;
k = md;
}
else {
r1 = md-1;
}
}
an -= k;
cout << an << '\n';
}
}
}
return 0;
}
Compilation message (stderr)
bridges.cpp: In function 'int main()':
bridges.cpp:108:9: warning: unused variable 'x2' [-Wunused-variable]
108 | int x2 = fnd(1,1,m,1,1);
| ^~
# | 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... |