#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 |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
480 KB |
Output is correct |
3 |
Correct |
51 ms |
600 KB |
Output is correct |
4 |
Correct |
3 ms |
604 KB |
Output is correct |
5 |
Correct |
6 ms |
600 KB |
Output is correct |
6 |
Correct |
5 ms |
600 KB |
Output is correct |
7 |
Correct |
4 ms |
348 KB |
Output is correct |
8 |
Correct |
4 ms |
604 KB |
Output is correct |
9 |
Correct |
5 ms |
344 KB |
Output is correct |
10 |
Correct |
4 ms |
600 KB |
Output is correct |
11 |
Correct |
3 ms |
648 KB |
Output is correct |
12 |
Correct |
4 ms |
604 KB |
Output is correct |
13 |
Correct |
6 ms |
604 KB |
Output is correct |
14 |
Correct |
7 ms |
496 KB |
Output is correct |
15 |
Correct |
6 ms |
604 KB |
Output is correct |
16 |
Correct |
4 ms |
348 KB |
Output is correct |
17 |
Correct |
4 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4 ms |
4952 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4 ms |
4956 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4 ms |
4952 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
480 KB |
Output is correct |
3 |
Correct |
51 ms |
600 KB |
Output is correct |
4 |
Correct |
3 ms |
604 KB |
Output is correct |
5 |
Correct |
6 ms |
600 KB |
Output is correct |
6 |
Correct |
5 ms |
600 KB |
Output is correct |
7 |
Correct |
4 ms |
348 KB |
Output is correct |
8 |
Correct |
4 ms |
604 KB |
Output is correct |
9 |
Correct |
5 ms |
344 KB |
Output is correct |
10 |
Correct |
4 ms |
600 KB |
Output is correct |
11 |
Correct |
3 ms |
648 KB |
Output is correct |
12 |
Correct |
4 ms |
604 KB |
Output is correct |
13 |
Correct |
6 ms |
604 KB |
Output is correct |
14 |
Correct |
7 ms |
496 KB |
Output is correct |
15 |
Correct |
6 ms |
604 KB |
Output is correct |
16 |
Correct |
4 ms |
348 KB |
Output is correct |
17 |
Correct |
4 ms |
344 KB |
Output is correct |
18 |
Runtime error |
4 ms |
4952 KB |
Execution killed with signal 11 |
19 |
Halted |
0 ms |
0 KB |
- |