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>
#define int long long
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pb push_back
using namespace std;
signed main(){
ios_base::sync_with_stdio();
cin.tie(0);cout.tie(0);
int n,m;
cin>>n>>m;
vector <int> u(m+1),v(m+1),w(m+1);
for(int i=1;i<=m;i++){
cin>>u[i]>>v[i]>>w[i];
}
int qu;cin>>qu;
while(qu--){
int type,ver,x;
cin>>type>>ver>>x;
if(type==1)w[ver]=x;
else{
vector <pair <int,int> > g[n+1];
for(int i=1;i<=m;i++){
g[u[i]].pb({v[i],w[i]});
g[v[i]].pb({u[i],w[i]});
}
vector <int> vis(n+1);
vis[ver]=1;
int cnt=1;
queue <int> q;q.push(ver);
while(!q.empty()){
int v=q.front();
q.pop();
for(auto to : g[v]){
if(!vis[to.ff] && to.ss>=x){
vis[to.ff]=1;
cnt++;
q.push(to.ff);
}
}
}
cout<<cnt<<"\n";
}
}
}
/*
3 4
1 2 5
2 3 2
3 1 4
2 3 8
5
2 1 5
1 4 1
2 2 5
1 1 1
2 3 2
*/
# | 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... |