Submission #1007396

#TimeUsernameProblemLanguageResultExecution timeMemory
1007396Ahmed57Connecting Supertrees (IOI20_supertrees)C++17
100 / 100
138 ms22224 KiB
#include "bits/stdc++.h" #include "supertrees.h" using namespace std; int pr[100001]; int find(int x){ if(x==pr[x])return x; return pr[x] = find(pr[x]); } void mergegroup(int a,int b){ a = find(a); b = find(b); if(a==b)return ; pr[a] = b; } int pr2[100001]; int find2(int x){ if(x==pr2[x])return x; return pr2[x] = find2(pr2[x]); } void mergegroup2(int a,int b){ a = find2(a); b = find2(b); if(a==b)return ; pr2[a] = b; } int construct(vector<vector<int>> p){ int n = p.size(); vector<vector<int>> B; vector<int> x(n,0); for(int i = 0;i<n;i++){ B.push_back(x); } //phase 1 for(int i = 0;i<n;i++){ pr[i] = i; } for(int i = 0;i<n;i++){ for(int j = 0;j<n;j++){ if(p[i][j]==3){ return 0; } if(i==j)continue; if(p[i][j]){ mergegroup(i,j); } } } for(int i = 0;i<n;i++){ for(int j = 0;j<n;j++){ if(i==j)continue; if(find(i)==find(j)){ if(p[i][j]==0){ return 0; } }else{ if(p[i][j]){ return 0; } } } } //phase 2 for(int i = 0;i<n;i++){ pr2[i] = i; } for(int i = 0;i<n;i++){ for(int j = 0;j<n;j++){ if(i==j)continue; if(p[i][j]==1){ mergegroup2(i,j); } } } for(int i = 0;i<n;i++){ for(int j = 0;j<n;j++){ if(i==j)continue; if(find2(i)==find2(j)){ if(p[i][j]!=1){ return 0; } }else{ if(p[i][j]==1){ return 0; } } } } for(int i = 0;i<n;i++){ if(i==find(i)){ vector<int> lol; for(int j = 0;j<n;j++){ if(find(i)==find(j)){ lol.push_back(j); } } vector<int> ror[n]; for(int j:lol){ ror[find2(j)].push_back(j); } vector<int> nah; for(int j = 0;j<n;j++){ if(ror[j].size()){ nah.push_back(j); } for(int e = 1;e<ror[j].size();e++){ B[ror[j][e-1]][ror[j][e]]=1; B[ror[j][e]][ror[j][e-1]]=1; } } if(nah.size()==2){ return 0; } for(int j = 0;j<nah.size();j++){ int a = nah[j] , b = nah[(j+1)%nah.size()]; B[a][b] = 1; B[b][a] = 1; } } } for(int i = 0;i<n;i++)B[i][i] = 0; build(B); return 1; }

Compilation message (stderr)

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:106:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  106 |                 for(int e = 1;e<ror[j].size();e++){
      |                               ~^~~~~~~~~~~~~~
supertrees.cpp:114:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  114 |             for(int j = 0;j<nah.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...