Submission #587785

#TimeUsernameProblemLanguageResultExecution timeMemory
587785almothana05Connecting Supertrees (IOI20_supertrees)C++14
96 / 100
238 ms24184 KiB
#include "supertrees.h" #include <vector> #include<bits/stdc++.h> using namespace std; vector<vector<int> >erg; vector<int>cmp[2000] , comp; int vis[2000] , visi[2000] , f[2000]; set<int> s; int construct(vector<vector<int>> p) { int menge = p.size() , pl = 1; for(int i = 0 ; i < menge ; i++){ erg.push_back(vector<int>() ); for(int j = 0 ; j < menge ; j++){ erg[i].push_back(0); } } for(int i = 0 ; i < menge ; i++){ if(p[i][i] != 1){ return 0; } p[i][i] = 1; } for(int i = 0 ; i < menge ; i++){ if(vis[i] == 0){ vis[i] = pl; for(int j = 0 ; j < menge ; j++){ if(p[i][j] == 1){ cmp[pl].push_back(j); vis[j] = pl; } } int fl = 1; for(int j = 0 ; j < menge ; j++){ for(int k = 0 ; k < cmp[pl].size() ; k++){ if(p[i][j] != p[cmp[pl][k]][j]){ fl = 0; break; } } } for(int j = 0 ; j < cmp[pl].size() - 1 ; j++){ erg[cmp[pl][j]][cmp[pl][j + 1]] = 1; erg[cmp[pl][j + 1]][cmp[pl][j]] = 1; } if(fl == 0){ return 0; } f[pl] = i; // cout << pl << " " << i << "\n"; pl++; } } int c = 1; for(int i = 1 ; i < pl; i++){ s.clear(); comp.clear(); int kan = f[i]; if(visi[i] == 0){ visi[i] = c; for(int j = 0 ; j < menge ; j++){ if(p[kan][j] == 2){ // cout << f[vis[j]] << ' ' << i << "\n"; if(s.count(vis[j]) == 0){ assert(i != vis[j]); s.insert(vis[j]); comp.push_back(f[vis[j]]); visi[vis[j]] = c; } } } s.insert(i); int fl = 1; // cout << "yo\n"; comp.push_back(kan); for(int k = 0 ; k < comp.size() ; k++){ for(int j = 0 ; j < menge ; j++){ // if(p[kan][j] == 0 && p[comp[k][j]] != 0){ // return 0; // } // if(p[kan][j] == 0 && p[comp[k][j]] != 0){ // return 0; // } if(p[comp[k]][j] != p[j][comp[k]]){ fl = 0; break; } if(vis[j] != vis[comp[k]] && s.count(vis[j]) == 1 && p[comp[k]][j] != 2){ fl = 0; break; } if(s.count(vis[j]) == 0 && p[comp[k]][j] == 2){ fl = 0; break; } } } if(comp.size() == 2){ return 0; } if(fl == 0){ return 0; } // assert(comp.size() > 2); for(int j = 0 ; j < comp.size() ; j++){ // cout << comp[j] << ' '; if(j != (j + 1) % comp.size()){ erg[comp[j]][comp[(j + 1) % comp.size()]] = 1; erg[comp[(j + 1) % comp.size()] ][comp[j]] = 1; // assert() } } // cout << "\n"; } } build(erg); return 1; }

Compilation message (stderr)

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:34:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     for(int k = 0 ; k < cmp[pl].size() ; k++){
      |                     ~~^~~~~~~~~~~~~~~~
supertrees.cpp:41:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |    for(int j = 0 ; j < cmp[pl].size() - 1 ; j++){
      |                    ~~^~~~~~~~~~~~~~~~~~~~
supertrees.cpp:76:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |             for(int k = 0 ; k < comp.size() ; k++){
      |                             ~~^~~~~~~~~~~~~
supertrees.cpp:105:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  105 |             for(int j = 0 ; j < comp.size() ; j++){
      |                             ~~^~~~~~~~~~~~~
supertrees.cpp:107:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  107 |                 if(j != (j + 1) % comp.size()){
      |                    ~~^~~~~~~~~~~~~~~~~~~~~~~~
#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...