Submission #303485

#TimeUsernameProblemLanguageResultExecution timeMemory
303485Jarif_RahmanConnecting Supertrees (IOI20_supertrees)C++17
Compilation error
0 ms0 KiB
#include "supertrees.h" #include <bits/stdc++.h> #define pb push_back #define f first #define sc second using namespace std; typedef long long int ll; typedef string str; vector<vector<int>> v; vector <vector<int>> dsu1; vector <int> dsu2; void unite(int a, int b){ if(dsu2[a] == dsu2[b]) return; int x = dsu2[a], y = dsu2[b]; if(dsu1[x].size() < dsu1.size()){ while(!dsu1[x].empty()){ int ss = dsu1[x].back(); dsu1[x].pop_back(); dsu2[ss] = y; dsu1[y].pb(ss); } } else{ while(!dsu1[y].empty()){ int ss = dsu1[y].back(); dsu1[y].pop_back(); dsu2[ss] = x; dsu1[x].pb(ss); } } } int construct(vector<vector<int>> p){ v.clear(); dsu1.clear(); dsu2.clear(); int n = p.size(); v = vector<vector<int>>(n, vector<int>(n, 0)); dsu1 = vector<vector<int>>(n); dsu2 = vector<int>(n); for(int i = 0; i < n ; i++) dsu1[i].pb(i); for(int i = 0; i < n; i++) dsu2[i] = i; for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) if(p[i][j] != 0) unite(i, j); for(auto sth: dsu1){ if(sth.size() < 2) continue; vector <int> two, one; for(int x: sth){ int o = 0,tw = 0; for(int k = 0; k < n; k++){ if(k == x) continue; if(y == 1) o++; } if(o == 0) two.pb(x); else one.pb(x); } for(int i = 0; i < one.size() - 1; i++){ int x = one[i], y = one[i+1]; v[x][y] = 1; v[y][x] = 1; } if(two.size() == 0) continue; if(two.size() == 1){ bl = 0; break; } for(int i = 0; i < two.size() - 1; i++){ int x = two[i], y = two[i+1]; v[x][y] = 1; v[y][x] = 1; } if(one.size() == 0){ int x = two[0], y = two.back(); v[x][y] = 1; v[y][x] = 1; } else{ int x = two[0], y = two.back(), z = one[0]; v[x][z] = 1; v[z][x] = 1; v[y][z] = 1; v[z][y] = 1; } } if(!bl) return 0; build(v); return 1; }

Compilation message (stderr)

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:50:20: error: 'y' was not declared in this scope
   50 |                 if(y == 1) o++;
      |                    ^
supertrees.cpp:47:23: warning: unused variable 'tw' [-Wunused-variable]
   47 |             int o = 0,tw = 0;
      |                       ^~
supertrees.cpp:55:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |         for(int i = 0; i < one.size() - 1; i++){
      |                        ~~^~~~~~~~~~~~~~~~
supertrees.cpp:62:13: error: 'bl' was not declared in this scope; did you mean 'll'?
   62 |             bl = 0;
      |             ^~
      |             ll
supertrees.cpp:65:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |         for(int i = 0; i < two.size() - 1; i++){
      |                        ~~^~~~~~~~~~~~~~~~
supertrees.cpp:83:9: error: 'bl' was not declared in this scope; did you mean 'll'?
   83 |     if(!bl) return 0;
      |         ^~
      |         ll