This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define F first
#define S second
#define rep(i,a,b) for(int i=a;!(a==b&&i!=b)&&((i<=b&&b>=a)||(i>=b&&a>=b));i+=(a<=b?1:-1))
#define pb push_back
#define Fbitl __builtin_ffs
#define bit1 __builtin_popcount
#define pi acos(-1)
//#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string.h>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<vl> vvl;
struct path {
int u;
int w;
int num;
};
bool visa[1002];
vector <path> x[1002];
pair<int, int> b[1002];
int dfs(int idx, int w) {
visa[idx] = false;
int res = 0;
for (auto i : x[idx]) {
if (visa[i.u] && w <= i.w) {
res += dfs(i.u, w) + 1;
}
}
return res;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
memset(visa, 1, sizeof(visa));
int n, m, q, a, l, r, w;
cin >> n >> m;
for (int i = 1; i <= m; i++) {
cin >> l >> r >> w;
b[i] = { l,r };
path z;
z.u = l; z.w = w; z.num = i;
x[r].pb(z);
swap(z.u, r);
x[r].pb(z);
}
cin >> q;
vi ans;
while (q--) {
cin >> a;
if (a == 1) {
cin >> a >> w;
for (int i = 0; i < x[b[a].F].size();i++) {
if (x[b[a].F][i].num == a) x[b[a].F][i].w = w;
}
swap(b[a].F, b[a].S);
for (int i = 0; i < x[b[a].F].size(); i++) {
if (x[b[a].F][i].num == a) x[b[a].F][i].w = w;
}
}
else {
memset(visa, 1, sizeof(visa));
cin >> a >> w;
ans.push_back(dfs(a, w) + 1);
}
}
for (auto i : ans)cout << i << endl;
return 0;
}
Compilation message (stderr)
bridges.cpp: In function 'int main()':
bridges.cpp:66:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<path>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | for (int i = 0; i < x[b[a].F].size();i++) {
| ~~^~~~~~~~~~~~~~~~~~
bridges.cpp:70:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<path>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | for (int i = 0; i < x[b[a].F].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... |