Submission #306540

#TimeUsernameProblemLanguageResultExecution timeMemory
306540vivaan_guptaConnecting Supertrees (IOI20_supertrees)C++14
Compilation error
0 ms0 KiB
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <ratio> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #include <climits> #include "supertrees.h" #define ll long long #define ld long double #define mp make_pair #define pb push_back #define in insert #define vll vector<ll> #define endl "\n" #define f first #define s second // #define int ll using namespace std; struct DSU { int connected; vector<int> par, sz; void init(int n) { par = sz = vector<int> (n + 1, 0); for(int i = 1; i <= n; i++) par[i] = i, sz[i] = 1; connected = n; } int getPar(int u) { while(u != par[u]) { par[u] = par[par[u]]; u = par[u]; } return u; } int getSize(int u) { return sz[getPar(u)]; } void unite(int u, int v) { int par1 = getPar(u), par2 = getPar(v); if(par1 == par2) return; connected--; if(sz[par1] > sz[par2]) swap(par1, par2); sz[par2] += sz[par1]; sz[par1] = 0; par[par1] = par[par2]; } }; int construct(std::vector<std::vector<int>> p) { DSU g; int n = p.size(); g.init(n-1); std::vector<std::vector<int>> ans; for (int i = 0; i < n; i++) { std::vector<int> row; row.resize(n); ans.push_back(row); } bool ok = false; bool ok2 = false; for(int i = 0;i<n;i++){ for(int j = 0;j<n;j++){ ok |= (p[i][j] == 1); ok2 |= (p[i][j] == 2); } } if(!ok2 && !ok){ for(int i =0;i<n;i++){ for(int j =0;j<n;j++){ ans[i][j] =0; } } build(ans); return 1; } if(!ok){ for(int i =0;i<n;i++){ for(int j =i+1;j<n;j++){ if(p[i][j] == 2){ g.unite(i,j); } } } map<int,int> col; vector<int> wow[n+1]; int c = 1; for(int i =0;i<n;i++){ int op = g.getPar(i); if(col[op] == 0){ col[op] = c; c++; } wow[col[op]].pb(i); } c--; for(int i =0;i<n;i++){ for(int j =0;j<n;j++){ ans[i][j] = 0; } } for(int i =1;i<=c;i++){ if(wow[i].size() == 1) continue; for(int j= 0;j<wow[i].size()-1;j++){ ans[wow[i][j]][wow[i][j+1]] = 1; ans[wow[i][j+1]][wow[i][j]] = 1; } ans[wow[i].back()][wow[i][0]] = 1; ans[wow[i][0]][wow[i].back()] = 1; } build(ans); return 1; } for(int i =0;i<n;i++){ for(int j =i+1;j<n;j++){ if(p[i][j] > 0){ g.unite(i,j); } } } map<int,int> col; vector<int> wow[n+1]; int c = 1; for(int i =0;i<n;i++){ int op = g.getPar(i); if(col[op] == 0){ col[op] = c; c++; } wow[col[op]].pb(i); } c--; for(int i =0;i<n;i++){ for(int j =0;j<n;j++){ ans[i][j] = 0; } } for(int i =1;i<=c;i++){ int sz = wow[i].size(); ok = false; int cnt = 0; int idx = -1,idx2 = -1; int x = -1,y = -1; vector<pll> gg1,gg2; for(int j =0;j<sz;j++){ for(int k = j+1;k<sz;k++){ if(p[wow[i][j]][wow[i][k]] == 2){ ok = true; } else if(p[wow[i][j]][wow[i][k]] == 1) { cnt++; // idx = wow[i][j]; // idx2 = wow[i][k]; gg.pb(mp(idx,idx2)); gg2.pb(mp(x,y)); // x = j; // y = k; } } } if(!ok){ for(int j =0;j<sz-1;j++){ ans[wow[i][j]][wow[i][j+1]] = 1; ans[wow[i][j+1]][wow[i][j]] = 1; } continue; } if(gg.empty()){ for(int j = 0;j<sz-1;j++){ ans[wow[i][j]][wow[i][j+1]] = 1; ans[wow[i][j+1]][wow[i][j]] = 1; } ans[wow[i].back()][wow[i][0]] = 1; ans[wow[i][0]][wow[i].back()] = 1; continue; } // assert(cnt == 1); for(auto p:gg1){ ans[p.f][p.s] = 1; ans[p.s][p.f] = 1; } // ans[idx][idx2] = 1; // ans[idx2][idx] = 1; vector<int> v; for(int j = 0;j<sz;j++){ bool poss =true; for(int k = 0;k<gg2.size();k++){ poss &= (j != gg2[k].f); } if(poss) v.pb(wow[i][j]); } for(int j = 0;j<v.size()-1;j++){ ans[v[j]][v[j+1]] = 1; ans[v[j+1]][v[j]] = 1; } ans[v.back()][v[0]] = 1; ans[v[0]][v.back()] = 1; } build(ans); return 1; } // void solve(){ // } // signed main(){ // ios_base::sync_with_stdio(0); // cin.tie(NULL); // // freopen(".in","r",stdin);freopen(".out","w",stdout); // ll tt=1; // // cin >> tt; // while(tt--){ // solve(); // } // }

Compilation message (stderr)

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:152:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  152 |    for(int j= 0;j<wow[i].size()-1;j++){
      |                 ~^~~~~~~~~~~~~~~~
supertrees.cpp:192:10: error: 'pll' was not declared in this scope; did you mean 'vll'?
  192 |   vector<pll> gg1,gg2;
      |          ^~~
      |          vll
supertrees.cpp:192:13: error: template argument 1 is invalid
  192 |   vector<pll> gg1,gg2;
      |             ^
supertrees.cpp:192:13: error: template argument 2 is invalid
supertrees.cpp:202:6: error: 'gg' was not declared in this scope; did you mean 'gg2'?
  202 |      gg.pb(mp(idx,idx2));
      |      ^~
      |      gg2
supertrees.cpp:35:12: error: request for member 'push_back' in 'gg2', which is of non-class type 'int'
   35 | #define pb push_back
      |            ^~~~~~~~~
supertrees.cpp:203:10: note: in expansion of macro 'pb'
  203 |      gg2.pb(mp(x,y));
      |          ^~
supertrees.cpp:216:6: error: 'gg' was not declared in this scope; did you mean 'gg2'?
  216 |   if(gg.empty()){
      |      ^~
      |      gg2
supertrees.cpp:226:14: error: 'begin' was not declared in this scope; did you mean 'std::begin'?
  226 |   for(auto p:gg1){
      |              ^~~
      |              std::begin
In file included from /usr/include/c++/9/string:54,
                 from /usr/include/c++/9/bitset:47,
                 from supertrees.cpp:2:
/usr/include/c++/9/bits/range_access.h:105:37: note: 'std::begin' declared here
  105 |   template<typename _Tp> const _Tp* begin(const valarray<_Tp>&);
      |                                     ^~~~~
supertrees.cpp:226:14: error: 'end' was not declared in this scope; did you mean 'std::end'?
  226 |   for(auto p:gg1){
      |              ^~~
      |              std::end
In file included from /usr/include/c++/9/string:54,
                 from /usr/include/c++/9/bitset:47,
                 from supertrees.cpp:2:
/usr/include/c++/9/bits/range_access.h:107:37: note: 'std::end' declared here
  107 |   template<typename _Tp> const _Tp* end(const valarray<_Tp>&);
      |                                     ^~~
supertrees.cpp:236:24: error: request for member 'size' in 'gg2', which is of non-class type 'int'
  236 |    for(int k = 0;k<gg2.size();k++){
      |                        ^~~~
supertrees.cpp:237:24: error: invalid types 'int[int]' for array subscript
  237 |     poss &= (j != gg2[k].f);
      |                        ^
supertrees.cpp:241:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  241 |   for(int j = 0;j<v.size()-1;j++){
      |                 ~^~~~~~~~~~~