#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
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++) {
| ~~^~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
81 ms |
608 KB |
Output is correct |
4 |
Correct |
20 ms |
612 KB |
Output is correct |
5 |
Correct |
17 ms |
544 KB |
Output is correct |
6 |
Correct |
15 ms |
528 KB |
Output is correct |
7 |
Correct |
14 ms |
460 KB |
Output is correct |
8 |
Correct |
17 ms |
524 KB |
Output is correct |
9 |
Correct |
19 ms |
488 KB |
Output is correct |
10 |
Correct |
13 ms |
460 KB |
Output is correct |
11 |
Correct |
17 ms |
556 KB |
Output is correct |
12 |
Correct |
12 ms |
460 KB |
Output is correct |
13 |
Correct |
19 ms |
552 KB |
Output is correct |
14 |
Correct |
18 ms |
552 KB |
Output is correct |
15 |
Correct |
20 ms |
560 KB |
Output is correct |
16 |
Correct |
14 ms |
480 KB |
Output is correct |
17 |
Correct |
15 ms |
476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
620 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
716 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
512 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
620 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
81 ms |
608 KB |
Output is correct |
4 |
Correct |
20 ms |
612 KB |
Output is correct |
5 |
Correct |
17 ms |
544 KB |
Output is correct |
6 |
Correct |
15 ms |
528 KB |
Output is correct |
7 |
Correct |
14 ms |
460 KB |
Output is correct |
8 |
Correct |
17 ms |
524 KB |
Output is correct |
9 |
Correct |
19 ms |
488 KB |
Output is correct |
10 |
Correct |
13 ms |
460 KB |
Output is correct |
11 |
Correct |
17 ms |
556 KB |
Output is correct |
12 |
Correct |
12 ms |
460 KB |
Output is correct |
13 |
Correct |
19 ms |
552 KB |
Output is correct |
14 |
Correct |
18 ms |
552 KB |
Output is correct |
15 |
Correct |
20 ms |
560 KB |
Output is correct |
16 |
Correct |
14 ms |
480 KB |
Output is correct |
17 |
Correct |
15 ms |
476 KB |
Output is correct |
18 |
Runtime error |
2 ms |
620 KB |
Execution killed with signal 11 |
19 |
Halted |
0 ms |
0 KB |
- |