Submission #255794

#TimeUsernameProblemLanguageResultExecution timeMemory
255794mehrdad_sohrabiBridges (APIO19_bridges)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> typedef unsigned int ll; typedef long double ld; #define pb push_back #define pii pair < int , int > #define F first #define S second #define endl '\n' #define int unsigned in #define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math") #define kill(x) return cout<<x<<'\n', 0; using namespace std; const int N=5e4+2,sq=700; vector <pair <int,pii > > yy,yal; bool vis[N*2]; bool vis2[N*2]; ll par[N],sz[N]; ll getpar(ll v){ if (par[v]==v) return v; return par[v]=getpar(par[v]); } inline void mrg(ll v,ll u){ ll u1=getpar(u),v1=getpar(v); if (u1==v1) return ; if (sz[u1]>sz[v1])swap(u1,v1); par[u1]=v1; sz[v1]+=sz[u1]; } ll pp[N],zz[N]; ll gg(ll v){ if (pp[v]==v) return v; return pp[v]=gg(pp[v]); } inline void merg(ll v,ll u){ ll v1=gg(v),u1=gg(u); if (v1==u1) return ; if (zz[u1]>zz[v1]) swap(v1,u1); pp[u1]=v1; zz[v1]+=zz[u1]; } ll ans[N*2]; vector <pair <int,pii> > q; int32_t main(){ sync; ll n,m; scanf("%d %d",&n,&m); for (int i=1;i<=m;i++){ ll u,v,w; scanf("%d %d %d",&u,&v,&w); // com.pb(w); yy.pb({w,{u,v}}); } ll q1; scanf("%d",&q1); while(q1--){ ll u,v,w; scanf("%d %d %d",&u,&v,&w); // com.pb(w); q.pb({u,{v,w}}); } for (int i=0;i<q.size();i+=sq){ vector <pii> g; for (int j=i;j<min(i+sq,(int)q.size());j++){ if (q[j].F==1) vis[q[j].S.F-1]=1; else{ g.pb({q[j].S.S,j}); } } memset(par,0,sizeof par); memset(sz,0,sizeof sz); for (int j=1;j<=n;j++){ sz[j]=1; par[j]=j; } yal.clear(); for (int j=0;j<yy.size();j++){ if (vis[j]) continue; yal.pb(yy[j]); } sort(yal.begin(),yal.end()); sort(g.begin(),g.end()); reverse(g.begin(),g.end()); ll cnt=0; for (int j=yal.size()-1;j>-1;j--){ while(cnt<g.size() && g[cnt].F>yal[j].F){ for (int k=i;k<min(i+sq,(ll)q.size());k++){ if (q[k].F==1){ vis2[q[k].S.F-1]=0; ll v=yy[q[k].S.F-1].S.F,u=yy[q[k].S.F-1].S.S; pp[v]=getpar(v); pp[u]=getpar(u); zz[pp[v]]=sz[pp[v]]; zz[pp[u]]=sz[pp[u]]; pp[pp[v]]=pp[v]; pp[pp[u]]=pp[u]; } else{ ll v=q[k].S.F; pp[v]=getpar(v); zz[pp[v]]=sz[pp[v]]; pp[pp[v]]=pp[v]; } } ll id=g[cnt].S; for (int k=id;k>=i;k--){ if (q[k].F==2) continue; ll v=yy[q[k].S.F-1].S.F,u=yy[q[k].S.F-1].S.S; if (vis2[q[k].S.F-1]) continue; vis2[q[k].S.F-1]=1; if (q[k].S.S>=g[cnt].F){ merg(u,v); } } for (int k=id+1;k<min(i+sq,(ll)q.size());k++){ if (q[k].F==2) continue; ll v=yy[q[k].S.F-1].S.F,u=yy[q[k].S.F-1].S.S; if (vis2[q[k].S.F-1]) continue; vis2[q[k].S.F-1]=1; if (yy[q[k].S.F-1].F>=g[cnt].F){ merg(u,v); } } ans[id]=zz[gg(q[id].S.F)]; cnt++; } // for (int jj=0;jj<yal[j].size();jj++){ mrg(yal[j].S.F,yal[j].S.S); //} } while(cnt<g.size()){ for (int k=i;k<min(i+sq,(ll)q.size());k++){ if (q[k].F==1){ vis2[q[k].S.F-1]=0; ll v=yy[q[k].S.F-1].S.F,u=yy[q[k].S.F-1].S.S; pp[v]=getpar(v); pp[u]=getpar(u); zz[pp[v]]=sz[pp[v]]; zz[pp[u]]=sz[pp[u]]; pp[pp[u]]=pp[u]; pp[pp[v]]=pp[v]; } else{ ll v=q[k].S.F; pp[v]=getpar(v); zz[pp[v]]=sz[pp[v]]; pp[pp[v]]=pp[v]; } } ll id=g[cnt].S; for (int k=id;k>=i;k--){ if (q[k].F==2) continue; ll v=yy[q[k].S.F-1].S.F,u=yy[q[k].S.F-1].S.S; if (vis2[q[k].S.F-1]) continue; vis2[q[k].S.F-1]=1; if (q[k].S.S>=g[cnt].F){ merg(u,v); } } for (int k=id+1;k<min(i+sq,(ll)q.size());k++){ if (q[k].F==2) continue; ll v=yy[q[k].S.F-1].S.F,u=yy[q[k].S.F-1].S.S; if (vis2[q[k].S.F-1]) continue; vis2[q[k].S.F-1]=1; if (yy[q[k].S.F-1].F>=g[cnt].F){ merg(u,v); } } ans[id]=zz[gg(q[id].S.F)]; cnt++; } for (int j=i;j<(min(i+sq,(ll)q.size()));j++){ if (q[j].F==1){ yy[q[j].S.F-1].F=q[j].S.S; vis[q[j].S.F-1]=0; } } } for (int i=0;i<q.size();i++){ if (q[i].F==2) printf("%d \n",ans[i]); } }

Compilation message (stderr)

bridges.cpp:14:11: error: expected initializer before 'N'
 const int N=5e4+2,sq=700;
           ^
bridges.cpp:15:23: error: wrong number of template arguments (1, should be 2)
 vector <pair <int,pii > > yy,yal;
                       ^
In file included from /usr/include/c++/7/bits/stl_algobase.h:64:0,
                 from /usr/include/c++/7/bits/char_traits.h:39,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from bridges.cpp:1:
/usr/include/c++/7/bits/stl_pair.h:198:12: note: provided for 'template<class _T1, class _T2> struct std::pair'
     struct pair
            ^~~~
bridges.cpp:15:25: error: template argument 1 is invalid
 vector <pair <int,pii > > yy,yal;
                         ^
bridges.cpp:15:25: error: template argument 2 is invalid
bridges.cpp:16:10: error: 'N' was not declared in this scope
 bool vis[N*2];
          ^
bridges.cpp:17:11: error: 'N' was not declared in this scope
 bool vis2[N*2];
           ^
bridges.cpp:18:8: error: 'N' was not declared in this scope
 ll par[N],sz[N];
        ^
bridges.cpp:18:14: error: 'N' was not declared in this scope
 ll par[N],sz[N];
              ^
bridges.cpp: In function 'll getpar(ll)':
bridges.cpp:20:9: error: 'par' was not declared in this scope
     if (par[v]==v) return v;
         ^~~
bridges.cpp:21:12: error: 'par' was not declared in this scope
     return par[v]=getpar(par[v]);
            ^~~
bridges.cpp: In function 'void mrg(ll, ll)':
bridges.cpp:26:9: error: 'sz' was not declared in this scope
     if (sz[u1]>sz[v1])swap(u1,v1);
         ^~
bridges.cpp:27:5: error: 'par' was not declared in this scope
     par[u1]=v1;
     ^~~
bridges.cpp:28:5: error: 'sz' was not declared in this scope
     sz[v1]+=sz[u1];
     ^~
bridges.cpp: At global scope:
bridges.cpp:30:7: error: 'N' was not declared in this scope
 ll pp[N],zz[N];
       ^
bridges.cpp:30:13: error: 'N' was not declared in this scope
 ll pp[N],zz[N];
             ^
bridges.cpp: In function 'll gg(ll)':
bridges.cpp:32:9: error: 'pp' was not declared in this scope
     if (pp[v]==v) return v;
         ^~
bridges.cpp:32:9: note: suggested alternative: 'pb'
     if (pp[v]==v) return v;
         ^~
         pb
bridges.cpp:33:12: error: 'pp' was not declared in this scope
     return pp[v]=gg(pp[v]);
            ^~
bridges.cpp:33:12: note: suggested alternative: 'pb'
     return pp[v]=gg(pp[v]);
            ^~
            pb
bridges.cpp: In function 'void merg(ll, ll)':
bridges.cpp:38:9: error: 'zz' was not declared in this scope
     if (zz[u1]>zz[v1]) swap(v1,u1);
         ^~
bridges.cpp:39:5: error: 'pp' was not declared in this scope
     pp[u1]=v1;
     ^~
bridges.cpp:39:5: note: suggested alternative: 'pb'
     pp[u1]=v1;
     ^~
     pb
bridges.cpp:40:5: error: 'zz' was not declared in this scope
     zz[v1]+=zz[u1];
     ^~
bridges.cpp: At global scope:
bridges.cpp:42:8: error: 'N' was not declared in this scope
 ll ans[N*2];
        ^
bridges.cpp:43:22: error: wrong number of template arguments (1, should be 2)
 vector <pair <int,pii> > q;
                      ^
In file included from /usr/include/c++/7/bits/stl_algobase.h:64:0,
                 from /usr/include/c++/7/bits/char_traits.h:39,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from bridges.cpp:1:
/usr/include/c++/7/bits/stl_pair.h:198:12: note: provided for 'template<class _T1, class _T2> struct std::pair'
     struct pair
            ^~~~
bridges.cpp:43:24: error: template argument 1 is invalid
 vector <pair <int,pii> > q;
                        ^
bridges.cpp:43:24: error: template argument 2 is invalid
bridges.cpp: In function 'int32_t main()':
bridges.cpp:48:14: error: expected ';' before 'i'
     for (int i=1;i<=m;i++){
              ^
bridges.cpp:48:14: error: 'i' was not declared in this scope
bridges.cpp:48:14: note: suggested alternative: 'in'
     for (int i=1;i<=m;i++){
              ^
              in
bridges.cpp:48:22: error: expected ')' before ';' token
     for (int i=1;i<=m;i++){
                      ^
bridges.cpp:48:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
     for (int i=1;i<=m;i++){
     ^~~
bridges.cpp:48:23: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
     for (int i=1;i<=m;i++){
                       ^
bridges.cpp:9:22: warning: unused variable 'in' [-Wunused-variable]
 #define int unsigned in
                      ^
bridges.cpp:48:10: note: in expansion of macro 'int'
     for (int i=1;i<=m;i++){
          ^~~
bridges.cpp:48:23: error: 'i' was not declared in this scope
     for (int i=1;i<=m;i++){
                       ^
bridges.cpp:4:12: error: request for member 'push_back' in 'q', which is of non-class type 'int'
 #define pb push_back
            ^
bridges.cpp:60:11: note: in expansion of macro 'pb'
         q.pb({u,{v,w}});
           ^~
bridges.cpp:63:14: error: expected ';' before 'i'
     for (int i=0;i<q.size();i+=sq){
              ^
bridges.cpp:63:22: error: request for member 'size' in 'q', which is of non-class type 'int'
     for (int i=0;i<q.size();i+=sq){
                      ^~~~
bridges.cpp:63:28: error: expected ')' before ';' token
     for (int i=0;i<q.size();i+=sq){
                            ^
bridges.cpp:63:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
     for (int i=0;i<q.size();i+=sq){
     ^~~
bridges.cpp:63:29: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
     for (int i=0;i<q.size();i+=sq){
                             ^
bridges.cpp:9:22: warning: unused variable 'in' [-Wunused-variable]
 #define int unsigned in
                      ^
bridges.cpp:63:10: note: in expansion of macro 'int'
     for (int i=0;i<q.size();i+=sq){
          ^~~
bridges.cpp:63:32: error: 'sq' was not declared in this scope
     for (int i=0;i<q.size();i+=sq){
                                ^~
bridges.cpp:63:32: note: suggested alternative: 'q'
     for (int i=0;i<q.size();i+=sq){
                                ^~
                                q
bridges.cpp:181:14: error: expected ';' before 'i'
     for (int i=0;i<q.size();i++){
              ^
bridges.cpp:181:22: error: request for member 'size' in 'q', which is of non-class type 'int'
     for (int i=0;i<q.size();i++){
                      ^~~~
bridges.cpp:181:28: error: expected ')' before ';' token
     for (int i=0;i<q.size();i++){
                            ^
bridges.cpp:181:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
     for (int i=0;i<q.size();i++){
     ^~~
bridges.cpp:181:29: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
     for (int i=0;i<q.size();i++){
                             ^
bridges.cpp:9:22: warning: unused variable 'in' [-Wunused-variable]
 #define int unsigned in
                      ^
bridges.cpp:181:10: note: in expansion of macro 'int'
     for (int i=0;i<q.size();i++){
          ^~~
bridges.cpp:47:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d",&n,&m);
     ~~~~~^~~~~~~~~~~~~~~
bridges.cpp:55:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&q1);
     ~~~~~^~~~~~~~~~
bridges.cpp:58:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %d",&u,&v,&w);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~