Submission #733705

#TimeUsernameProblemLanguageResultExecution timeMemory
733705tigarConnecting Supertrees (IOI20_supertrees)C++14
21 / 100
953 ms2097152 KiB
#include <bits/stdc++.h> #include "supertrees.h" using namespace std; typedef long long ll; vector<int> jedan[1010], dva[1010], nula[1010]; bool check[1010]; vector<int>lin; vector<int>cc[1010]; bool provera(int x, std::vector<std::vector<int>>p, int cmp) { lin.push_back(x); cc[cmp].push_back(x); int n=p.size(); for(int i=0; i<jedan[x].size(); i++) { if(check[jedan[x][i]])continue; check[jedan[x][i]]=true; if(jedan[x].size()!=jedan[jedan[x][i]].size())return false; for(int j=0; j<jedan[x].size(); j++) { if(jedan[x][j]!=jedan[jedan[x][i]][j])return false; } } for(int i=0; i<dva[x].size(); i++) { if(check[dva[x][i]])continue; check[dva[x][i]]=true; if(nula[x].size()!=nula[dva[x][i]].size())return false; if(nula[x].size()<=n/2) {for(int j=0; j<nula[x].size(); j++) { if(nula[x][j]!=nula[dva[x][i]][j])return false; }} else { for(int j=0; j<jedan[x].size(); j++) { if(jedan[x][j]!=0 and jedan[dva[x][i]][j]==0)return false; if(jedan[x][j]==0 and jedan[dva[x][i]][j]!=0)return false; } for(int j=0; j<dva[x].size(); j++) { if(dva[x][j]!=0 and dva[dva[x][i]][j]==0)return false; if(dva[x][j]==0 and dva[dva[x][i]][j]!=0)return false; } } if(!provera(dva[x][i], p, cmp))return false; } return true; } int construct(std::vector<std::vector<int>>p) { int n=p.size(); for(int i=0; i<n; i++) { for(int j=0; j<n; j++) { if(p[i][j]==1)jedan[i].push_back(j); else if(p[i][j]==2)dva[i].push_back(j); else if(p[i][j]==3)return 0; else nula[i].push_back(j); } } int br=1; for(int i=0; i<n; i++) { if(check[i])continue; if(!provera(i, p, br))return 0; br++; } vector<vector<int> > ans(n); for(int i=0; i<n; i++){ans[i].resize(n, 0);} for(int i=0; i<lin.size(); i++) { for(int j=1; j<jedan[lin[i]].size(); j++) { ans[jedan[lin[i]][j]][jedan[lin[i]][j-1]]=1; ans[jedan[lin[i]][j-1]][jedan[lin[i]][j]]=1; } } for(int i=1; i<br; i++) { for(int j=0; j<cc[i].size(); j++) { //cout<<cc[i][j]<<" "; if(cc[i].size()==2)return 0; ans[cc[i][j]][cc[i][(j+1)%cc[i].size()]]=1; ans[cc[i][(j+1)%cc[i].size()]][cc[i][j]]=1; } //cout<<endl; } for(int i=0; i<n; i++) { ans[i][i]=0; } //for(int i=0; i<n; i++){for(int j=0; j<n; j++)cout<<ans[i][j]<<" "; cout<<endl;} build(ans); return 1; } /*int main() { int n; cin>>n; vector<vector<int> >p; for(int i=0; i<n; i++) { vector<int>pp(n); for(int j=0; j<n; j++) { cin>>pp[j]; } p.push_back(pp); } cout<<construct(p); } */

Compilation message (stderr)

supertrees.cpp: In function 'bool provera(int, std::vector<std::vector<int> >, int)':
supertrees.cpp:17:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     for(int i=0; i<jedan[x].size(); i++)
      |                  ~^~~~~~~~~~~~~~~~
supertrees.cpp:22:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |         for(int j=0; j<jedan[x].size(); j++)
      |                      ~^~~~~~~~~~~~~~~~
supertrees.cpp:27:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for(int i=0; i<dva[x].size(); i++)
      |                  ~^~~~~~~~~~~~~~
supertrees.cpp:32:26: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   32 |         if(nula[x].size()<=n/2)
      |            ~~~~~~~~~~~~~~^~~~~
supertrees.cpp:33:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |         {for(int j=0; j<nula[x].size(); j++)
      |                       ~^~~~~~~~~~~~~~~
supertrees.cpp:39:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |             for(int j=0; j<jedan[x].size(); j++)
      |                          ~^~~~~~~~~~~~~~~~
supertrees.cpp:44:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |             for(int j=0; j<dva[x].size(); j++)
      |                          ~^~~~~~~~~~~~~~
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:77:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |     for(int i=0; i<lin.size(); i++)
      |                  ~^~~~~~~~~~~
supertrees.cpp:79:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |         for(int j=1; j<jedan[lin[i]].size(); j++)
      |                      ~^~~~~~~~~~~~~~~~~~~~~
supertrees.cpp:88:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |         for(int j=0; j<cc[i].size(); j++)
      |                      ~^~~~~~~~~~~~~
#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...