Submission #541781

#TimeUsernameProblemLanguageResultExecution timeMemory
541781Tenis0206Connecting Supertrees (IOI20_supertrees)C++17
21 / 100
204 ms24012 KiB
#include <bits/stdc++.h> //#define test #ifndef test #include "supertrees.h" #endif // testing using namespace std; #ifdef test vector<vector<int>> in; void build(vector<vector<int>> v) { int n = v.size(); for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { cout<<v[i][j]<<' '; } cout<<'\n'; } } #endif // testing vector<vector<int>> rez; int t[1005],rang[1005]; int reprezentant(int x) { if(x==t[x]) { return x; } t[x] = reprezentant(t[x]); return t[x]; } void uneste(int x, int y) { x = reprezentant(x); y = reprezentant(y); if(x==y) { return; } if(rang[x]<rang[y]) { t[x] = y; rang[y] += rang[x]; } else { t[y] = x; rang[x] += y; } } int construct(vector<vector<int>> p) { int n = p.size(); for(int i=0;i<n;i++) { t[i] = i; rang[i] = 1; } for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(p[i][j] && i!=j) { if(p[i][j]==3) { return 0; } uneste(i,j); } } } rez.resize(n); for(int i=0;i<n;i++) { rez[i].resize(n); } for(int i=0;i<n;i++) { vector<int> v; for(int j=0;j<n;j++) { if(reprezentant(j)==i) { v.push_back(j); } } for(int j=0;j<v.size();j++) { for(int k=j+1;k<v.size();k++) { if(!p[v[j]][v[k]]) { return 0; } } } for(int j=1;j<v.size();j++) { rez[v[j-1]][v[j]] = rez[v[j]][v[j-1]] = 1; } } build(rez); return 1; } #ifdef test int main() { freopen("nr.in","r",stdin); freopen("nr.out","w",stdout); int n; cin>>n; in.resize(n); for(int i=0;i<n;i++) { in[i].resize(n); } for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { cin>>in[i][j]; } } construct(in); return 0; } #endif // test

Compilation message (stderr)

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