Submission #1090025

#TimeUsernameProblemLanguageResultExecution timeMemory
1090025onlk97Connecting Supertrees (IOI20_supertrees)C++14
0 / 100
1 ms348 KiB
#include "supertrees.h" #include <vector> #include <bits/stdc++.h> using namespace std; struct DSU{ vector <int> dsu; void init(int n){ dsu.clear(); for (int i=0; i<=n; i++) dsu.push_back(i); } int prt(int n){ if (dsu[n]==n) return n; return dsu[n]=prt(dsu[n]); } void unn(int u,int v){ dsu[prt(u)]=dsu[prt(v)]; } }; int construct(vector <vector <int> > p){ int n=p.size(); DSU d; d.init(n); vector <vector <int> > op(n,vector <int>(n,0)); for (int i=0; i<n; i++){ for (int j=i+1; j<n; j++){ if (p[i][j]==1){ d.unn(i,j); op[i][j]=1; op[j][i]=1; } if (p[i][j]==3) return 0; } } for (int i=0; i<n; i++){ for (int j=i+1; j<n; j++){ if ((p[i][j]==1)!=(d.prt(i)==d.prt(j))) return 0; } } for (int i=0; i<n; i++){ if (p[i]!=p[d.prt(i)]) return 0; } bool done[n]; for (int i=0; i<n; i++) done[i]=0; for (int i=0; i<n; i++){ if (d.prt(i)!=i||done[i]) continue; set <int> s; s.insert(d.prt(i)); for (int j=i+1; j<n; j++){ if (p[i][j]==2) s.insert(d.prt(j)); } if (s.size()<3) return 0; vector <int> vec; for (int j:s) vec.push_back(j); for (int j=0; j<s.size(); j++){ op[vec[j]][vec[(j+1)%s.size()]]=1; op[vec[(j+1)%s.size()]][vec[j]]=1; } for (int j:vec){ done[j]=1; for (int k=0; k<n; k++){ if (p[j][k]==2&&s.find(d.prt(k))==s.end()) return 0; } } } build(op); return 1; }

Compilation message (stderr)

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:53:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::set<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |         for (int j=0; j<s.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...