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 pb push_back
using namespace std;
const int N = 5e4+5;
struct bridge{
int a,b,val;
bridge(){
a = b = val = 0;
}
};
int n,m,q;
bool vis[N];
vector<bridge> e;
vector< pair<int,int> > adj[N];
int dfs(int v,int val) {
int cnt = 1;
vis[v] = 1;
for (auto i : adj[v]) {
if (i.second >= val && !vis[i.first])
cnt += dfs(i.first,val);
}
return cnt;
}
main() {
cin >> n >> m;
e.resize(m+1);
for (int i = 1; i <= m; i++) {
cin >> e[i].a >> e[i].b >> e[i].val;
adj[e[i].a].pb({e[i].b,e[i].val});
adj[e[i].b].pb({e[i].a,e[i].val});
}
cin >> q;
for (int type,x,y;q--;) {
cin >> type >> x >> y;
if (type == 1) {
int a = e[x].a, b = e[x].b,val = e[x].val;
adj[a].erase(find(adj[a].begin(),adj[a].end(),make_pair(b,val)));
adj[b].erase(find(adj[b].begin(),adj[b].end(),make_pair(a,val)));
e[x].val = y;
adj[a].pb({b,y});
adj[b].pb({a,y});
}
else {
cout << dfs(x,y) <<'\n';
fill(vis,vis+n+1,0);
}
}
}
Compilation message (stderr)
bridges.cpp:24:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main() {
^
# | 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... |