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 ll long long int
#define pb push_back
#define pii pair<int,int>
#define ff first
#define ss second
#define sz size()
const int N = 5e4 + 1;
using namespace std;
int n, m, x[N], y[N], w[N], q, vis[N], ans;
vector <pii> v[N];
void dfs(int nd, int wgh){
if(vis[nd]) return;
ans++;
vis[nd] = 1;
for(auto i: v[nd]){
if(wgh <= i.ss) dfs(i.ff,wgh);
}
}
int main(){
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n >> m;
for(int i = 1; i <= m; i++){
cin >> x[i] >> y[i] >> w[i];
v[x[i]].pb({y[i],w[i]});
v[y[i]].pb({x[i],w[i]});
}
cin >> q;
while(q--){
int t, a, b;
cin >> t >> a >> b;
if(t == 1){
for(int i = 0; i < (int)v[x[a]].sz; i++){
if(v[x[a]][i].ff == y[a] and v[x[a]][i].ss == w[a]){
v[x[a]][i] = {y[a],b};
break;
}
}
for(int i = 0; i < (int)v[y[a]].sz; i++){
if(v[y[a]][i].ff == x[a] and v[y[a]][i].ss == w[a]){
v[y[a]][i] = {x[a],b};
w[a] = b;
break;
}
}
}
else{
ans = 0;
for(int i = 1; i <= n; i++) vis[i] = 0;
dfs(a,b);
cout << ans << '\n';
}
// if(t == 1 and a == 3 and b == 1) break;
}
// for(int i = 1; i <= n; i++){
// cout << i << '\n';
// for(auto j: v[i]) cout << j.ff << ' ' << j.ss << '\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... |