Submission #349467

#TimeUsernameProblemLanguageResultExecution timeMemory
349467evnConnecting Supertrees (IOI20_supertrees)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #include "supertrees.h" using namespace std; #define f first #define s second #define pb push_back #define mp make_pair #define sz(a) a.size() typedef long long ll; typedef pair<int, int> pii; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; int cmp[1005]; int cmpSize[1005]; vector<vector<int>> adj; int r = 0; int cs = 0; int N; void dfs(int u){ cmp[u] = r; cs++; for(int i = 0; i < N;i ++){ if(p[u][i] != 0 && cmp[i] == -1){ dfs(i); } } } int dsu[1005]; int sz[1005]; int find(int u){ if(dsu[u] == u)return u; return dsu[u] = find(dsu[u]); } int construct(vector<vector<int>> p){ N = p.size(); adj.resize(N); vector<vector<int>> edges; edges.resize(N); for(int i = 0; i < N; i++){ adj[i].resize(N); edges[i].resize(N); dsu[i] = i; sz[i] = 1; for(int j = 0;j < N;j ++){ adj[i][j] = p[i][j]; } } memset(cmp, -1, sizeof(cmp)); for(int i = 0; i < N; i++){ if(cmp[i] == -1){ cs = 0; r++; dfs(i); cmpSize[r] = cs; } } for(int i = 0; i < N;i ++){ int g = 0; for(int j =0;j < N; j++){ g = max(g, p[i][j]); } if(cmpSize[cmp[i]] <= g && cmpSize[cmp[i]] != 1)return 0; } //0 = different components //1 = same branch //2 = in da cycle. can't have multiple cycles in one connected component //dsu to store the branches for(int i = 0; i < N; i++){ for(int j =0;j < N; j++){ if(p[i][j] == 1){ merge(i,j); } } } //store the possible parents of branches set<int> pa; vector<int> parents; for(int i = 0; i < N;i ++){ pa.insert(find(i)); } for(int u : pa)parents.pb(u); //add edges between parents that are in the same cycle int prevCmp[N]; int fCmp[N]; memset(fCmp, -1, sizeof(fCmp)); memset(prevCmp, -1, sizeof(prevCmp)); for(int i = 0; i < parents.size(); i++){ int curr = parents[i]; int comp = cmp[curr]; if(fCmp[curr] == -1){ fCmp[comp] = curr; } //find the previous one in curr's connected comp if(prevCmp[comp] != -1){ //add edge edges[prevCmp[comp]][curr] = 1; edges[curr][prevCmp[comp]] = 1; } prevCmp[comp] = curr; } //create the loop in each component for(int i = 1; i <= r; i++){ if(prevCmp[i] != fCmp[i]){ edges[prevCmp[i]][fCmp[i]] = 1; edges[fCmp[i]][prevCmp[i]] = 1; } } //add edges in the branches int prevD[N]; memset(prevD, -1, sizeof(prevD)); for(int i = 0; i < N; i++){ if(prevD[find(i)] != -1){ edges[prevD[find(i)]][i] = 1; edges[i][prevD[find(i)]] = 1; } prevD[find(i)] = i; } return 1; }

Compilation message (stderr)

supertrees.cpp: In function 'void dfs(int)':
supertrees.cpp:25:6: error: 'p' was not declared in this scope
   25 |   if(p[u][i] != 0 && cmp[i] == -1){
      |      ^
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:73:14: error: no matching function for call to 'merge(int&, int&)'
   73 |     merge(i,j);
      |              ^
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from supertrees.cpp:1:
/usr/include/c++/9/bits/stl_algo.h:4949:5: note: candidate: 'template<class _IIter1, class _IIter2, class _OIter> _OIter std::merge(_IIter1, _IIter1, _IIter2, _IIter2, _OIter)'
 4949 |     merge(_InputIterator1 __first1, _InputIterator1 __last1,
      |     ^~~~~
/usr/include/c++/9/bits/stl_algo.h:4949:5: note:   template argument deduction/substitution failed:
supertrees.cpp:73:14: note:   candidate expects 5 arguments, 2 provided
   73 |     merge(i,j);
      |              ^
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from supertrees.cpp:1:
/usr/include/c++/9/bits/stl_algo.h:4999:5: note: candidate: 'template<class _IIter1, class _IIter2, class _OIter, class _Compare> _OIter std::merge(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, _Compare)'
 4999 |     merge(_InputIterator1 __first1, _InputIterator1 __last1,
      |     ^~~~~
/usr/include/c++/9/bits/stl_algo.h:4999:5: note:   template argument deduction/substitution failed:
supertrees.cpp:73:14: note:   candidate expects 6 arguments, 2 provided
   73 |     merge(i,j);
      |              ^
supertrees.cpp:89:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |  for(int i = 0; i < parents.size(); i++){
      |                 ~~^~~~~~~~~~~~~~~~