/*
VENI VIDI VICI
*/
// #pragma GCC optimize("Ofast","unroll-all-loops","fast-math","no-stack-protector","give-no-fuck")
#include <bits/stdc++.h>
// #include <iostream>
// #include <vector>
// #include <algorithm>
// #include <set>
// #include <map>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i,x, n) for (int i = (x); i < (n); ++i)
#define repr(i,x, n) for (int i = (n) - 1; i >= (x); --i)
mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count());
// #define sum accumulate
//using i128 = __int128;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using str = string;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vpi = vector<pair<int, int>>;
using vvi = vector<vi>;
using sll = set<ll>;
template<class T>
istream& operator>>(istream& is, vector<T>& v) {
for(auto &i:v) is>>i;
return is;
}
template<class T1,class T2>
istream& operator>>(istream& is, pair<T1,T2>& p) {
is>>p.fi>>p.se;
return is;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
for(const auto &i:v) os<<i<<' ';
return os;
}
template<class T1,class T2>
ostream& operator<<(ostream& os, const pair<T1,T2>& p) {
os<<p.fi<<' '<<p.se; return os;
}
void pyn(bool x)
{
cout<<(x?"YES":"NO")<<endl;
}
void pYN(bool x)
{
cout<<(x?"Yes":"No")<<endl;
}
void pAB(bool x)
{
cout<<(x?"Alice":"Bob")<<endl;
}
ll powmod(ll a,ll b,ll modulo)
{
if(b==0){
return 1;
}
ll temp=powmod(a,b/2,modulo);
if(b%2==0){
return (temp*temp)%modulo;
}
else{
return (a*((temp*temp)%modulo))%modulo;
}
}
bool Prime(ll n){
for (ll i = 2; i*i <= n; i++)
if (n % i == 0)
return false;
return (n>1);
}
void readIO() {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
}
void solve();
int main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// readIO();
int uwu=1;
// cin>>uwu;
for(int tc=1;tc<=uwu;tc++) {
// cout<<"Case #"<<tc<<": ";
solve();
}
return 0;
}
const int N=2e5+100,K=1000;
int x[N],y[N],w[N],t[N],c[N],u[N];
int seen[N],par[N],sz[N],ans[N];
int get(int x){return (par[x]==x?x:get(par[x]));}
stack<pair<int,int>> st;
void merge(int x,int y)
{
x=get(x),y=get(y);
if(x==y)
{
st.push({0,0});
return;
}
if(sz[x]<sz[y])swap(x,y);
sz[x]+=sz[y];
par[y]=x;
st.push({x,y});
}
void undo()
{
par[st.top().second]=st.top().second;
sz[st.top().first]-=sz[st.top().second];
st.pop();
}
ll n,m;
void solve()
{
cin>>n>>m;
for(int i=1;i<=m;i++)
{
cin>>x[i]>>y[i]>>w[i];
}
int q;
cin>>q;
while(q>0)
{
int curq=min(q,K);
vpi edg;
for(int i=1;i<=curq;i++)
{
cin>>t[i]>>u[i]>>c[i];
ans[i]=0;
if(t[i]==1)
seen[u[i]]=i;
else
edg.pb({c[i],-i});
}
for(int i=1;i<=n;i++)
{
par[i]=i;
sz[i]=1;
}
vl rem;
for(int j=1;j<=m;j++)
{
if(!seen[j])
{
edg.pb({w[j],j});
}
else
{
rem.pb(j);
}
}
sort(rall(edg));
for(auto wer:edg)
{
int we=wer.first,i=wer.second;
if(i<0)
{
// qry
i=-i;
int nead=0;
for(int j=1;j<i;j++)if(t[j]==1)seen[u[j]]=j;
for(auto j:rem)
{
if(seen[j]<i)
{
if(c[seen[j]]>=we)
{
merge(x[j],y[j]);
nead++;
}
}
else
{
if(w[j]>=we)
{
merge(x[j],y[j]);
nead++;
}
}
}
ans[i]=sz[get(u[i])];
while(nead--)
{
undo();
}
}
else
{
// add edge
merge(x[i],y[i]);
}
}
for(int j=1;j<=curq;j++)
{
if(t[j]==2)
{
cout<<ans[j]<<endl;
}
}
q-=curq;
}
}
Compilation message (stderr)
bridges.cpp: In function 'void readIO()':
bridges.cpp:90:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
90 | freopen("input.txt", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
bridges.cpp:91:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
91 | freopen("output.txt", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~| # | 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... |