이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define pb push_back
int n,m,num=sqrt(100000),t,u[100005],v[100005],w[100005],e[100005];
int op[100005],a[100005],b[100005],mx=-1,group[100005],it1,it2;
int p[50005],sz[50005],e2[100005],top,ans[100005],hsh[100005];
int p2[50005],sz2[50005],l,r;
set<pair<int,int> > s;
vector<pair<int,int> > g;
vector<tuple<int,int,int> > answer;
stack<pair<int,int> > stk;
int f(int a)
{
if(p[a]==a)return a;
return p[a]=f(p[a]);
}
void un(int b,int c)
{
sz[f(c)]+=sz[f(b)];
p[f(b)]=f(c);
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++)
{
scanf("%d%d%d",&u[i],&v[i],&w[i]);
e[i]=w[i];
s.insert(make_pair(e[i],i));
}
scanf("%d",&t);
for(int i=1;i<=t;i++)
{
scanf("%d%d%d",&op[i],&a[i],&b[i]);
group[i]=(i-1)/num+1;
mx=max(mx,group[i]);
}
for(int i=1;i<=mx;i++)
{
l=(i-1)*num+1;
r=min(t,i*num);
//printf("l=%d r=%d\n",l,r);
g.clear();
answer.clear();
for(auto it=s.begin();it!=s.end();it++)
{
stk.push({(*it).X,(*it).Y});
}
while(!stk.empty())
{
g.pb({stk.top().X,stk.top().Y});
stk.pop();
}
for(int j=1;j<=m;j++)hsh[j]=0;
for(int j=l;j<=r;j++)
{
if(op[j]==2)
{
answer.pb({b[j],a[j],j});
}else ++hsh[a[j]];
}
sort(answer.begin(),answer.end());
//printf("bothtoq\n");
for(int j=0;j<=(int)(answer.size()-1)/2;j++)
{
swap(answer[j],answer[(int)answer.size()-j-1]);
}
// for(auto [node,w]:g)
// {
// printf("%d %d\n",node,w);
// }
// for(auto [node,w,idx]:answer)
// {
// printf("%d %d %d\n",node,w,idx);
// }
it1=0,it2=0;
for(int j=1;j<=n;j++)p[j]=j,sz[j]=1;
for(int j=1;j<=m;j++)e2[j]=e[j];
/*for(int j=1;j<=m;j++)
{
printf("%d ",e[j]);
}
printf("plurm\n");
printf("\n");*/
top=1e9;
//printf("%d %d\n",g.size(),answer.size());
/*for(int i=0;i<g.size();i++)
{
printf("%d %d\n",g[i].X,g[i].Y);
}
printf("\n");
for(int i=1;i<=m;i++)
{
printf("%d ",hsh[i]);
}
printf("\n");*/
while(it2<(int)answer.size())
{
int w=g[it1].X,edge=g[it1].Y;
auto [w2,node,idx]=answer[it2];
//printf("%d %d\n",w,w2);
if(it1<(int)g.size())
{
if(w>=w2)
{
if(f(u[edge])!=f(v[edge])&&hsh[edge]==0)un(u[edge],v[edge]);
top=w;
++it1;
continue;
}
}
/*if(l==8)printf("%d %d\n",it1,it2);
if(l==8)
{
for(int i=1;i<=n;i++)
{
printf("%d ",f(i));
}
printf("\n");
for(int i=1;i<=n;i++)
{
printf("%d ",sz[f(i)]);
}
printf("\n");
}*/
//printf("%d %d\n",it1,it2);
//printf("answer = q no.%d\n",idx);
for(int i=1;i<=n;i++)p2[i]=p[i],sz2[i]=sz[i];
for(int j=l;j<=r;j++)
{
if(op[j]==1&&j<idx)
{
e2[a[j]]=b[j];
}
}
/*for(int j=1;j<=n;j++)
{
printf("%d ",p[j]);
}
printf("\n");
for(int j=1;j<=n;j++)
{
printf("%d ",sz[j]);
}
printf("\n");*/
for(int j=l;j<=r;j++)
{
if(op[j]==1)
{
if(e2[a[j]]>=b[idx])
if(f(u[a[j]])!=f(v[a[j]]))
{
un(u[a[j]],v[a[j]]);
}
}
}
ans[idx]=sz[f(node)];
for(int j=l;j<=r;j++)
{
if(op[j]==1&&j<idx)e2[a[j]]=e[a[j]];
}
for(int i=1;i<=n;i++)p[i]=p2[i],sz[i]=sz2[i];
++it2;
}
for(int j=l;j<=r;j++)
{
if(op[j]==1)
{
/*printf("size=%d\n",s.size());
for(auto [x,y]:s)
{
printf("krit3379=%d %d\n",x,y);
}
printf("\n");*/
//printf("krit=%d %d\n",e[a[j]],a[j]);
s.erase(s.find(make_pair(e[a[j]],a[j])));
//printf("%d %d\n",e[a[j]],a[j]);
e[a[j]]=b[j];
//printf("%d %d\n",e[a[j]],a[j]);
//printf("krit=%d %d\n",e[a[j]],a[j]);
s.insert(make_pair(e[a[j]],a[j]));
}
}
//printf("%d\n",s.size());
}
for(int i=1;i<=t;i++)
{
if(op[i]==2)printf("%d\n",ans[i]);
}
}
컴파일 시 표준 에러 (stderr) 메시지
bridges.cpp: In function 'int main()':
bridges.cpp:102:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
102 | auto [w2,node,idx]=answer[it2];
| ^
bridges.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
26 | scanf("%d%d",&n,&m);
| ~~~~~^~~~~~~~~~~~~~
bridges.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
29 | scanf("%d%d%d",&u[i],&v[i],&w[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
bridges.cpp:33:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | scanf("%d",&t);
| ~~~~~^~~~~~~~~
bridges.cpp:36:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
36 | scanf("%d%d%d",&op[i],&a[i],&b[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |