Submission #304324

#TimeUsernameProblemLanguageResultExecution timeMemory
304324Jarif_RahmanConnecting Supertrees (IOI20_supertrees)C++17
75 / 100
337 ms27512 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, dsu11; vector <int> dsu2, dsu12; 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); } } } void unite1(int a, int b){ if(dsu12[a] == dsu12[b]) return; int x = dsu12[a], y = dsu12[b]; if(dsu11[x].size() < dsu11.size()){ while(!dsu11[x].empty()){ int ss = dsu11[x].back(); dsu11[x].pop_back(); dsu12[ss] = y; dsu11[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(); dsu11.clear(); dsu12.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; dsu11 = dsu1; vector <int> zot(3, 0); dsu12 = dsu2; for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) if(p[i][j] != 0) unite(i, j); for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) if(i != j) zot[p[i][j]]++; bool bl = 1; for(auto sth: dsu1){ if(sth.size() < 2) continue; if(sth.size() == 2){ if(zot[1] == 0){ bl = 0; break; } else continue; } for(int i = 0; i < sth.size(); i++) for(int j = 0; j < sth.size(); j++){ if(i == j) continue; if(p[sth[i]][sth[j]] == 0){ bl = 0; break; } } } if(!bl) return 0; for(auto sth: dsu1){ if(sth.size() < 2) continue; vector <int> two, one; for(int x: sth) for(int y: sth){ if(x == y) continue; if(p[x][y] == 1) unite1(x, y); } for(int x: sth){ int o = 0,tw = 0; for(int k = 0; k < n; k++){ if(k == x) continue; if(p[x][k] == 1) o++; } if(o == 0) two.pb(x); else one.pb(x); } for(int a: sth){ if(dsu11[a].size() < 2) continue; for(int i = 0; i < dsu11[a].size() - 1; i++){ int x = dsu11[a][i], y = dsu11[a][i+1]; v[x][y] = 1; v[y][x] = 1; } } vector <int> oo; for(int a: sth) if(dsu11[a].size() > 0) oo.pb(dsu11[a][0]); for(int i = 1; i < oo.size(); i++){ int x = oo[i], y = oo[i-1]; v[x][y] = 1; v[y][x] = 1; } if(oo.size() > 1){ int x = oo[0], y = oo.back(); v[x][y] = 1; v[y][x] = 1; } } build(v); return 1; }

Compilation message (stderr)

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:79:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |         for(int i = 0; i < sth.size(); i++) for(int j = 0; j < sth.size(); j++){
      |                        ~~^~~~~~~~~~~~
supertrees.cpp:79:62: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |         for(int i = 0; i < sth.size(); i++) for(int j = 0; j < sth.size(); j++){
      |                                                            ~~^~~~~~~~~~~~
supertrees.cpp:96:23: warning: unused variable 'tw' [-Wunused-variable]
   96 |             int o = 0,tw = 0;
      |                       ^~
supertrees.cpp:106:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  106 |             for(int i = 0; i < dsu11[a].size() - 1; i++){
      |                            ~~^~~~~~~~~~~~~~~~~~~~~
supertrees.cpp:114:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  114 |         for(int i = 1; i < oo.size(); i++){
      |                        ~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...