이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//------------------------------------\\
// ------------------------------ \\
// | created by Dinh Manh Hung | \\
// | tht.onepunchac168 | \\
// | THPT CHUYEN HA TINH | \\
// | HA TINH, VIET NAM | \\
// | Siuuu | \\
// ------------------------------ \\
//------------------------------------\\
#include <bits/stdc++.h>
using namespace std;
#define task ""
#define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
#define ldb long double
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) begin(x),end(x)
#define uniquev(v) v.resize(unique(all(v))-v.begin())
#define rep(i,a,b) for (int i=a;i<=b;i++)
#define cntbit(v) __builtin_popcountll(v)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) ((1LL*a*b)/__gcd(a,b))
#define mask(x) (1LL<<(x))
#define readbit(x,i) ((x>>i)&1)
#define Yes cout << "Yes"
#define YES cout << "YES"
#define No cout << "No"
#define NO cout << "NO"
typedef int ll;
typedef pair <ll,ll> ii;
typedef pair <ll,ii> iii;
typedef pair <ii,ii> iiii;
ll dx[]= {1,-1,0,0,1,-1,1,-1};
ll dy[]= {0,0,-1,1,1,-1,-1,1};
const ldb PI = acos (-1);
//const ll mod=978846151;
//const ll base=29;
const ll mod=1e9+7;
const char nl = '\n';
inline int ReadInt()
{
char co;
for (co = getchar(); co < '0' || co > '9'; co = getchar());
int xo = co - '0';
for (co = getchar(); co >= '0' && co <= '9'; co = getchar())
xo = (xo<<1) + (xo<<3) + co - '0';
return xo;
}
void WriteInt(int xo)
{
if (xo > 9)
WriteInt(xo / 10);
putchar(xo % 10 + '0');
}
// DEBUG
/*
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
*/
/* END OF TEMPLATE*/
// ================= Solution =================//
void onepunchac168();
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
file(task);
int tests;
tests=1;
//cin>>tests;
while (tests--)
{
onepunchac168();
}
}
const int N=5e4+4;
const int M=1e5+5;
const int BLOCK=300;
int n,m,q;
ll ua[M],va[M],da[M];
ll t[M],a1[M],a2[M];
bool check[M];
ll ans[M];
bool ck[M];
struct DSU{
int lab[N];
void makeset (int u)
{
lab[u]=-1;
}
ll findset(int u)
{
if (lab[u]<0)
{
return u;
}
return lab[u]=findset(lab[u]);
}
void Union(int r,int s)
{
if (lab[r]>lab[s])
{
swap(r,s);
}
lab[r]+=lab[s];
lab[s]=r;
}
} dsu,dsua;
void onepunchac168()
{
cin>>n>>m;
for (int i=1;i<=m;i++)
{
cin>>ua[i]>>va[i]>>da[i];
}
cin>>q;
for (int i=1;i<=q;i++)
{
cin>>t[i]>>a1[i]>>a2[i];
}
for (int i=0;i<=q/BLOCK;i++)
{
int left=max(1,i*BLOCK);
int right=min(q,(i+1)*BLOCK-1);
vector <iii> cnt;
vector <ii> tmp;
for (int j=1;j<=m;j++)
{
check[j]=0;
}
for (int j=1;j<=n;j++)
{
dsu.makeset(j);
}
for (int j=left;j<=right;j++)
{
if (t[j]==1)
{
check[a1[j]]=1;
}
else
{
tmp.pb({a2[j],j});
}
}
for (int j=1;j<=m;j++)
{
if (check[j]==1)
{
continue;
}
cnt.pb({da[j],{ua[j],va[j]}});
}
sort (cnt.begin(),cnt.end(),greater <iii> ());
sort (tmp.begin(),tmp.end(),greater <ii> ());
ll ida=0;
for (auto v:tmp)
{
int id=v.se;
int s=a1[id];
while (ida<cnt.size()&&cnt[ida].fi>=v.fi)
{
int r=dsu.findset(cnt[ida].se.fi);
int s=dsu.findset(cnt[ida].se.se);
if (r!=s)
{
dsu.Union(r,s);
}
ida++;
}
vector <ll> opt;
vector <ii> target;
opt.pb(dsu.findset(s));
for (int j=id-1;j>=left;j--)
{
if (t[j]==1&&ck[a1[j]]==0)
{
ck[a1[j]]=1;
if (a2[j]>=v.fi){
target.pb({ua[a1[j]],va[a1[j]]});
opt.pb(dsu.findset(ua[a1[j]]));
opt.pb(dsu.findset(va[a1[j]]));
}
}
}
for (int j=id+1;j<=right;j++)
{
if (t[j]==1)
{
if (ck[a1[j]]==0)
{
ck[a1[j]]=1;
if (da[a1[j]]>=v.fi)
{
target.pb({ua[a1[j]],va[a1[j]]});
opt.pb(dsu.findset(ua[a1[j]]));
opt.pb(dsu.findset(va[a1[j]]));
}
}
}
}
for (auto v:opt)
{
dsua.makeset(v);
dsua.lab[v]=dsu.lab[v];
}
for (auto v:target)
{
int r=dsu.findset(v.fi);
int ss=dsu.findset(v.se);
r=dsua.findset(r);
ss=dsua.findset(ss);
if (r!=ss)
{
dsua.Union(r,ss);
}
}
int r=dsu.findset(s);
int ss=dsua.findset(r);
ans[id]=-dsua.lab[ss];
for (int j=left;j<=right;j++)
{
if (t[j]==1)
{
ck[a1[j]]=0;
}
}
}
for (int j=left;j<=right;j++)
{
if (t[j]==1)
{
da[a1[j]]=a2[j];
}
}
}
for (int i=1;i<=q;i++)
{
if (t[i]==1)
{
continue;
}
cout<<ans[i]<<nl;
}
}
// goodbye see ya
컴파일 시 표준 에러 (stderr) 메시지
bridges.cpp:1:1: warning: multi-line comment [-Wcomment]
1 | //------------------------------------\\
| ^
bridges.cpp: In function 'void onepunchac168()':
bridges.cpp:204:23: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
204 | while (ida<cnt.size()&&cnt[ida].fi>=v.fi)
| ~~~^~~~~~~~~~~
bridges.cpp: In function 'int main()':
bridges.cpp:15:66: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
15 | #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bridges.cpp:108:5: note: in expansion of macro 'file'
108 | file(task);
| ^~~~
bridges.cpp:15:99: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
15 | #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
bridges.cpp:108:5: note: in expansion of macro 'file'
108 | file(task);
| ^~~~
# | 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... |