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
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
ll n,m;
cin>>n>>m;
set<pair<ll,ll>>adj[n];
vector<array<ll,3>>edge;
for(ll i=0;i<m;i++){
ll u,v,d;
cin>>u>>v>>d;
u--,v--;
adj[u].insert({v,d});
adj[v].insert({u,d});
edge.pb({u,v,d});
}
vector<bool>used(n);
ll q;
cin>>q;
while(q--){
ll t;
cin>>t;
if(t==1){
ll b,r;
cin>>b>>r;
b--;
auto [u,v,d]=edge[b];
adj[u].erase({v,d});
adj[v].erase({u,d});
edge[b][2]=r;
d=r;
adj[u].insert({v,d});
adj[v].insert({u,d});
}
else{
ll s,w;
cin>>s>>w;
s--;
fill(all(used),0);
function <void(ll)> dfs=[&](ll x){
used[x]=true;
for(auto [y,d]:adj[x]){
if(d>=w&&!used[y]){
dfs(y);
}
}
};
dfs(s);
ll ans=0;
for(ll i=0;i<n;i++){
ans+=(used[i]==true);
}
cout<<ans<<"\n";
}
}
}
# | 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... |