Submission #755095

#TimeUsernameProblemLanguageResultExecution timeMemory
755095sofija6Connecting Supertrees (IOI20_supertrees)C++14
100 / 100
242 ms25088 KiB
#include "supertrees.h" #include <bits/stdc++.h> #define MAXN 1010 using namespace std; int d[MAXN]; int Root(int p) { while (d[p]!=p) { d[p]=d[d[p]]; p=d[p]; } return p; } void Join(int p,int q) { d[Root(p)]=d[Root(q)]; } int construct(std::vector<std::vector<int>> p) { int n=p.size(); for (int i=0;i<n;i++) { d[i]=i; for (int j=0;j<n;j++) { if (p[i][j]==3 || p[i][j]!=p[j][i]) return 0; if (i==j && p[i][j]!=1) return 0; } } vector<int> v[n+2]; for (int i=0;i<n;i++) { for (int j=0;j<n;j++) { if (p[i][j]==1) Join(i,j); } } vector<vector<int> > b; b.resize(n); for (int i=0;i<n;i++) b[i].resize(n); for (int i=0;i<n;i++) { if (i==Root(i)) continue; b[i][Root(i)]=1; b[Root(i)][i]=1; } bool cyc[n+2][n+2]; for (int i=0;i<n;i++) { for (int j=0;j<n;j++) cyc[i][j]=false; } for (int i=0;i<n;i++) { for (int j=0;j<n;j++) { if (p[i][j]==2) cyc[Root(i)][Root(j)]=true; } } vector<int> root[n+2]; for (int i=0;i<n;i++) { root[Root(i)].push_back(i); for (int j=0;j<n;j++) { if (!p[i][j] && (Root(i)==Root(j) || cyc[Root(i)][Root(j)])) return 0; if (p[i][j]==1 && (Root(i)!=Root(j) || cyc[Root(i)][Root(j)])) return 0; if (p[i][j]==2 && (Root(i)==Root(j) || !cyc[Root(i)][Root(j)])) return 0; } } bool vis[n+2]={false}; for (int i=0;i<n;i++) { if (vis[i] || Root(i)!=i) continue; set<int> s; vector<int> v; int cur=i; while (true) { s.insert(cur); v.push_back(cur); vis[cur]=true; bool next=false; for (int j=0;j<n;j++) { if (cyc[cur][j] && !s.count(j)) { cur=j; next=true; break; } } if (!next) break; } if (s.size()==2) return 0; if (s.size()==1) continue; for (int j=0;j<v.size();j++) { for (int k=0;k<v.size();k++) { if (j==k) continue; for (auto U : root[v[j]]) { for (auto V : root[v[k]]) { if (p[U][V]!=2) return 0; } } } } for (int j=0;j<v.size()-1;j++) { b[v[j]][v[j+1]]=1; b[v[j+1]][v[j]]=1; } b[v[v.size()-1]][v[0]]=1; b[v[0]][v[v.size()-1]]=1; } build(b); return 1; }

Compilation message (stderr)

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