Submission #340855

#TimeUsernameProblemLanguageResultExecution timeMemory
340855ogibogi2004Bridges (APIO19_bridges)C++14
Compilation error
0 ms0 KiB
#include<bits/stdc++.h> using namespace std; const int MAXN=5e4+6; const int MAXM=1e5+6; const int SQRT=600; int n,m,q; int ans[MAXM]; struct edge { int u,v,w; bool operator<(edge const& other)const { if(w!=other.w)return w<other.w; return v<other.v; } }; struct query { int type; int a,b; bool operator<(query const& other)const { if(b!=other.b)return b<other.b; return type<other.type; } }; struct query1 { int time; int s,w; bool operator<(query1 const& other)const { return w<other.w; } }; int e[MAXN]; vector<vector<query> >blocks; bool used[MAXM]; bool changed[MAXM]; int par[MAXN],rnk[MAXN],sz[MAXN]; struct save { int u,v,rnku,rnkv,szu,szv; }; stack<save>lol; int getRoot(int u) { if(u==par[u])return u; return getRoot(par[u]); } void join(int u,int v) { lol.push({u,v,rnk[u],rnk[v],sz[u],sz[v]}); if(rnk[u]>rnk[v]) { par[v]=u; sz[u]+=sz[v]; } else if(rnk[v]>rnk[u]) { par[u]=v; sz[v]+=sz[u]; } else { par[v]=u; ++rnk[v]; sz[u]+=sz[v]; } } void rollback() { save xd=lol.top();lol.pop(); par[xd.u]=xd.u; par[xd.v]=xd.v; sz[xd.u]=xd.szu; sz[xd.v]=xd.szv; rnk[xd.u]=xd.rnku; rnk[xd.v]=xd.rnkv; } void add_edge(edge o) { int u=getRoot(o.u); int v=getRoot(o.v); if(u!=v)join(u,v); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin>>n>>m; for(int i=0;i<m;++i) { cin>>e[i].u>>e[i].v>>e[i].w; } cin>>q; for(int i=0;i<q;++i) { if(blocks.size()==0||blocks.back().size()==SQRT)blocks.emplace_back(); int t; cin>>t; if(t==1) { int b,r; cin>>b>>r; --b; blocks.back().push_back({t,b,-r}); } if(t==2) { int w,s; cin>>s>>w; blocks.back().push_back({t,s,-w}); } } memset(ans,-1,sizeof(ans)); int s=0; vector<edge>unchanged;vector<query1>a;vector<int>used_edges; for(int i=0;i<blocks.size();++i) { for(auto ivan:blocks[i]) { if(ivan.type==1)changed[ivan.a]=1; } unchanged.clear(); for(int j=0;j<e.size();++j) { if(!changed[j])unchanged.push_back(e[j]); } sort(unchanged.begin(),unchanged.end()); for(int j=1;j<=n;++j) { par[j]=j;sz[j]=1; rnk[j]=1; } a.clear(); for(int j=0;j<blocks[i].size();++j) { if(blocks[i][j].type==2) { a.push_back({j+s,blocks[i][j].a,blocks[i][j].b}); } } sort(a.begin(),a.end()); used_edges.clear(); int pp=0; for(int j=0;j<a.size();++j) { used_edges.clear(); while(pp<unchanged.size()&&unchanged[pp].w<=a[j].w) { add_edge(unchanged[pp]);++pp; } for(int l=a[j].time-s;l>=0;--l) { if(blocks[i][l].type==1) { if(used[blocks[i][l].a]) { used[blocks[i][l].a]=1; continue; } if(blocks[i][l].b>a[j].w) { used[blocks[i][l].a]=1; continue; } int idx=blocks[i][l].a; int n1=getRoot(e[idx].u); int n2=getRoot(e[idx].v); if(n1!=n2) { join(n1,n2); used_edges.push_back(idx); } used[blocks[i][l].a]=1; } } for(int l=a[j].time-s;l<blocks[i].size();++l) { if(blocks[i][l].type==2)continue; if(used[blocks[i][l].a]) { continue; } int idx=blocks[i][l].a; if(e[idx].w>a[j].w) { used[idx]=1; continue; } int n1=getRoot(e[idx].u); int n2=getRoot(e[idx].v); if(n1!=n2) { join(n1,n2); used_edges.push_back(idx); } used[idx]=1; } ans[a[j].time]=sz[getRoot(a[j].s)]; for(int l=used_edges.size()-1;l>=0;--l) { rollback(); } for(int l=blocks[i].size()-1;l>=0;--l) { if(blocks[i][l].type==1) { used[blocks[i][l].a]=0; } } } for(int j=0;j<blocks[i].size();++j) { if(blocks[i][j].type==1) { e[blocks[i][j].a].w=blocks[i][j].b; changed[blocks[i][j].a]=0; } } s+=blocks[i].size(); } for(int i=0;i<=q;++i) { if(ans[i]!=-1)cout<<ans[i]<<'\n'; } return 0; }

Compilation message (stderr)

bridges.cpp: In function 'int main()':
bridges.cpp:95:13: error: request for member 'u' in 'e[i]', which is of non-class type 'int'
   95 |   cin>>e[i].u>>e[i].v>>e[i].w;
      |             ^
bridges.cpp:95:21: error: request for member 'v' in 'e[i]', which is of non-class type 'int'
   95 |   cin>>e[i].u>>e[i].v>>e[i].w;
      |                     ^
bridges.cpp:95:29: error: request for member 'w' in 'e[i]', which is of non-class type 'int'
   95 |   cin>>e[i].u>>e[i].v>>e[i].w;
      |                             ^
bridges.cpp:120:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<query> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  120 |  for(int i=0;i<blocks.size();++i)
      |              ~^~~~~~~~~~~~~~
bridges.cpp:127:19: error: request for member 'size' in 'e', which is of non-class type 'int [50006]'
  127 |   for(int j=0;j<e.size();++j)
      |                   ^~~~
bridges.cpp:129:43: error: no matching function for call to 'std::vector<edge>::push_back(int&)'
  129 |    if(!changed[j])unchanged.push_back(e[j]);
      |                                           ^
In file included from /usr/include/c++/9/vector:67,
                 from /usr/include/c++/9/queue:61,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:86,
                 from bridges.cpp:1:
/usr/include/c++/9/bits/stl_vector.h:1184:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = edge; _Alloc = std::allocator<edge>; std::vector<_Tp, _Alloc>::value_type = edge]'
 1184 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/9/bits/stl_vector.h:1184:35: note:   no known conversion for argument 1 from 'int' to 'const value_type&' {aka 'const edge&'}
 1184 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/9/bits/stl_vector.h:1200:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = edge; _Alloc = std::allocator<edge>; std::vector<_Tp, _Alloc>::value_type = edge]'
 1200 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/9/bits/stl_vector.h:1200:30: note:   no known conversion for argument 1 from 'int' to 'std::vector<edge>::value_type&&' {aka 'edge&&'}
 1200 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
bridges.cpp:138:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<query>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  138 |   for(int j=0;j<blocks[i].size();++j)
      |               ~^~~~~~~~~~~~~~~~~
bridges.cpp:148:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<query1>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  148 |   for(int j=0;j<a.size();++j)
      |               ~^~~~~~~~~
bridges.cpp:151:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  151 |    while(pp<unchanged.size()&&unchanged[pp].w<=a[j].w)
      |          ~~^~~~~~~~~~~~~~~~~
bridges.cpp:170:28: error: request for member 'u' in 'e[idx]', which is of non-class type 'int'
  170 |      int n1=getRoot(e[idx].u);
      |                            ^
bridges.cpp:171:28: error: request for member 'v' in 'e[idx]', which is of non-class type 'int'
  171 |      int n2=getRoot(e[idx].v);
      |                            ^
bridges.cpp:180:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<query>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  180 |    for(int l=a[j].time-s;l<blocks[i].size();++l)
      |                          ~^~~~~~~~~~~~~~~~~
bridges.cpp:188:15: error: request for member 'w' in 'e[idx]', which is of non-class type 'int'
  188 |     if(e[idx].w>a[j].w)
      |               ^
bridges.cpp:193:27: error: request for member 'u' in 'e[idx]', which is of non-class type 'int'
  193 |     int n1=getRoot(e[idx].u);
      |                           ^
bridges.cpp:195:27: error: request for member 'v' in 'e[idx]', which is of non-class type 'int'
  195 |     int n2=getRoot(e[idx].v);
      |                           ^
bridges.cpp:217:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<query>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  217 |   for(int j=0;j<blocks[i].size();++j)
      |               ~^~~~~~~~~~~~~~~~~
bridges.cpp:221:23: error: request for member 'w' in 'e[(& blocks.std::vector<std::vector<query> >::operator[](((std::vector<std::vector<query> >::size_type)i)))->std::vector<query>::operator[](((std::vector<query>::size_type)j)).query::a]', which is of non-class type 'int'
  221 |     e[blocks[i][j].a].w=blocks[i][j].b;
      |                       ^