이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define F first
#define S second
#define ull unsigned long long
#define db double
#define ldb long double
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define all(x) x.begin(), x.end()
const int mod = 1e9 + 7;
const int N = 1e5 + 7;
using namespace std;
using namespace __gnu_pbds;
ll n, m, k, p[N], tp, a, b, c, d, e, used[N];
pair <pair <ll, ll>, ll> w[N];
vector <ll> q;
set <pair <ll, ll>> g[N];
void dfs (ll v, ll x){
q.pb (v);
used[v] = 1;
for (auto i: g[v]){
if (used[i.F] == 0 && i.S >= x){
dfs (i.F, x);
}
}
}
signed main (){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= m; i++){
cin >> w[i].first.F >> w[i].first.S >> w[i].second;
a = w[i].first.F;
b = w[i].first.S;
c = w[i].second;
g[a].insert ({b, c});
g[b].insert ({a, c});
}
cin >> m;
while (m--){
cin >> tp;
if (tp == 1){
cin >> d >> e;
a = w[d].first.F;
b = w[d].first.S;
c = w[d].second;
g[a].erase ({b, c});
g[b].erase ({a, c});
w[d].second = e;
c = w[d].second;
g[a].insert ({b, c});
g[b].insert ({a, c});
}
else{
cin >> a >> b;
q.clear();
dfs (a, b);
for (auto i: q){
used[i] = 0;
}
cout << q.size() << '\n';
}
}
}
/*
9 12
1 9 4
1 2 5
2 3 7
2 4 3
4 3 6
3 6 4
8 7 10
6 7 5
5 8 1
9 5 7
5 4 12
6 8 2
2
4 7
5
1 6
5 3
4 8
5 8
1 5
*/
# | 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... |