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;
int n, m;
int cont = 0;
int pesos[100005];
bool vis[500004];
struct Puente
{
int v, idx;
};
vector <Puente> ady[1500004];
void ask(int curr, int peso)
{
//vis[curr] = true;
//cout<<curr<<".size "<< ady[curr].size()<<endl;
for (int i = 0; i < ady[curr].size(); i++)
{
//cout<<"ask "<<ady[curr][i].v<<" ";
if (vis[ady[curr][i].v] == false and pesos[ady[curr][i].idx] >= peso)
{
vis[ady[curr][i].v] = true;
//// cout<<"se visita "<<ady[curr][i].v<<endl;
// cout<<"ok"<<endl;
cont ++;
//cout<<"de "<<curr<<" se puede llegar a "<<ady[curr][i].v<<endl;
ask(ady[curr][i].v, peso);
} /*else
{
if (vis[ady[curr][i].v] == true)
{
cout<<ady[curr][i].v<<" ya visitado"<<endl;
}else
{
cout<<ady[curr][i].v<<" no resiste"<<endl;;
}
}*/
}
return;
}
int main()
{
cin>>n>>m;
Puente nuevo1, nuevo2;
int s1, s2, w;
for (int i = 1; i <= m; i++)
{
cin>>s1>>s2>>w;
nuevo1.v = s1;
nuevo1.idx = i;
nuevo2.v = s2;
nuevo2.idx = i;
ady[s1].push_back(nuevo2);
ady[s2].push_back(nuevo1);
pesos[i] = w;
}
int q; cin>>q;
int t, a, b;
for (int i = 0; i < q; i++)
{
cin>>t;
if (t == 1)
{
cin>>a>>b;
pesos[a] = b;
}else
{
cin>>a>>b;
fill(vis, vis + n+3, false);
vis[a] = true;
cont = 1;
ask(a, b);
cout<<cont<<"\n";
}
}
}
Compilation message (stderr)
bridges.cpp: In function 'void ask(int, int)':
bridges.cpp:23:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Puente>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | for (int i = 0; i < ady[curr].size(); i++)
| ~~^~~~~~~~~~~~~~~~~~
# | 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... |