이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// Bolatulu
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
#define kanagattandirilmagandiktarinizdan ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define pf push_front
#define eb emplace_back
#define ins insert
#define F first
#define S second
#define fx cout << fixed << setprecision(6);
#define md (tl+tr)/2
#define TL v+v, tl,md
#define TR v+v+1, md+1,tr
#define Tl t[v].l, tl,md
#define Tr t[v].r, md+1,tr
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define all(x) (x).begin(), (x).end()
#define int ll
#define cnk(n,k) mod(mod(f[(n)]*binpow(f[(n)-(k)],M-2))*binpow(f[(k)],M-2))
#define cnkf(n,k) mod(mod(f[(n)]*inv[(n)-(k)])*inv[(k)])
using namespace std;
typedef complex<double> cd;
struct mine{int l;int r;int i;};
struct edge{int u;int v;int w;};
struct tree{int l;int r;int val;};
bool cmp(edge a,edge b) {
return a.w>b.w;
}
mt19937 RR((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
int random(int l, int r){
return uniform_int_distribution<int>(l, r)(RR);
}
int M=998244353;
int mod1(int a,int b=M) {
if (a<0)
a=b+a%b;
return a % b;
}
int binpow(int a,int n,int m=M) {
a=mod1(a,m);
if (!n)
return 1;
if (n&1)
return (a * binpow(a,n-1))%m;
int x = binpow(a,n>>1);
return (x*x)%m;
}
const ll INF=1e18+7;
const int N=2e5+7;
int n,m,q,t[N],s[N],c[N],e1[N],e2[N],w[N],ans;
vector <pair <int,int>> g[N];
bool u[N];
void dfs(int v,int x) {
u[v]=true;
ans++;
for (auto now : g[v]) {
int to=now.F,i=now.S;
if (x<=w[i] and !u[to])
dfs(to,x);
}
}
void solve() {
cin >> n >> m;
for (int i=1;i<=m;i++) {
cin >> e1[i] >> e2[i] >> w[i];
g[e1[i]].eb(e2[i],i);
g[e2[i]].eb(e1[i],i);
}
cin >> q;
for (int i=0;i<q;i++) {
cin >> t[i] >> s[i] >> c[i];
if (t[i]==1) {
w[s[i]]=c[i];
} else {
for (int j=1;j<=n;j++)
u[j]=false;
ans=0;
dfs(s[i],c[i]);
cout << ans << '\n';
}
}
}
signed main() {
/*
freopen("sequence.in", "r", stdin);
freopen("sequence.out", "w", stdout);
*/
// fx
kanagattandirilmagandiktarinizdan
int test = 1, count = 1;
// cin >> test;
while (test--) {
// cout << "Case " << count << ":\n";
solve();
if (test) {
cout << '\n';
count++;
}
}
return 0;
}
// ctrl + shift + p make stress isis__Good isis__Generator
// g++ -std=c++17 (path) -o run
// .\run
# | 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... |