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 int long long
#define f first
#define s second
bool visited[1001];
vector<int> adj[1001];
pair<pair<int,int>,int> edges[1001];
int ans;
void dfs(int x,int wt){
if(visited[x])return;
visited[x]=true;
ans++;
for(int&i:adj[x]){
if(edges[i].s<wt)continue;
dfs(edges[i].f.f,wt);
dfs(edges[i].f.s,wt);
}
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n,m;
cin >> n >> m;
for(int i=1;i<=m;i++){
int a,b,c;cin>>a>>b>>c;
edges[i] = {{a,b},c};
adj[a].emplace_back(i);
adj[b].emplace_back(i);
}
int q;
cin >> q;
for(int i=1;i<=q;i++){
int type,a,b;cin>>type>>a>>b;
if(type==1){
edges[a].s = b;
} else {
for(bool&x:visited)x=false;
ans = 0;
dfs(a,b);
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... |