Submission #953762

#TimeUsernameProblemLanguageResultExecution timeMemory
953762Trisanu_DasConnecting Supertrees (IOI20_supertrees)C++17
46 / 100
175 ms24148 KiB
#include "supertrees.h" #include <vector> using namespace std; int par[1005]; int fi(int i){ if(par[i]==i) return i; else return par[i]=fi(par[i]); } void un(int i,int j){ par[fi(j)]=fi(i); } int construct(vector<vector<int>> p) { int n = p.size(); vector<vector<int>> ans; for (int i = 0; i < n; i++) { vector<int> row; row.resize(n); ans.push_back(row); } for(int i=0;i<n;i++) par[i]=i; for(int i=0;i<n;i++){ for(int j=i+1;j<n;j++){ if(p[i][j]==1&&fi(i)!=fi(j)){ ans[i][j]=ans[j][i]=1; un(i,j); } if(p[i][j]==3||(p[i][j]==0&&fi(i)==fi(j))) return 0; } } for(int i=0;i<n;i++){ vector<int> v; v.push_back(par[i]); for(int j=i+1;j<n;j++){ if(p[i][j]==2&&fi(i)!=fi(j)){ v.push_back(par[j]); un(i,j); } } if(v.size()==2) return 0; for(int k=0;k+1<v.size();k++) ans[v[k]][v[k+1]]=ans[v[k+1]][v[k]]=1; ans[v[0]][v[v.size()-1]]=ans[v[v.size()-1]][v[0]]=1; } for(int i=0;i<n;i++) ans[i][i]=0; build(ans); return 1; }

Compilation message (stderr)

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:56:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |         for(int k=0;k+1<v.size();k++)
      |                     ~~~^~~~~~~~~
supertrees.cpp:62:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   62 |     for(int i=0;i<n;i++)
      |     ^~~
supertrees.cpp:65:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   65 |  build(ans);
      |  ^~~~~
#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...