Submission #434593

#TimeUsernameProblemLanguageResultExecution timeMemory
434593pere_gilConnecting Supertrees (IOI20_supertrees)C++14
40 / 100
284 ms22084 KiB
#include "supertrees.h" #include "bits/stdc++.h" using namespace std; int p[1005]; void init(int n){ for(int i=0;i<n;i++) p[i]=i; } int find_set(int n){ return (p[n]==n) ? n : p[n]=find_set(p[n]); } bool same_set(int a, int b){ return find_set(a)==find_set(b); } void union_set(int a, int b){ if(!same_set(a,b)) p[find_set(a)]=find_set(b); } void form_group(vector<int> &g, vector<vector<int> > &v, bool is_2){ if(g.size()==1) return; if(!is_2){ for(int i=1;i<g.size();i++) v[g[i]][g[i-1]]=v[g[i-1]][g[i]]=1; return; } for(int i=0;i<g.size();i++){ int j=(i+1)%g.size(); v[g[i]][g[j]]=v[g[j]][g[i]]=1; } } int construct(vector<vector<int> > v){ int n=v.size(); init(n); for(int i=0;i<n;i++) for(int j=0;j<n;j++) if(v[i][j]) union_set(i,j); vector<vector<int> > g(n); for(int i=0;i<n;i++) g[find_set(i)].push_back(i); for(int i=0;i<n;i++) for(int j=0;j<n;j++) if(same_set(i,j) && v[i][j]==0) return 0; bool is_2=false; for(int i=0;i<n;i++) for(int j=0;j<n;j++) if(v[i][j]==2) is_2=true; for(int i=0;i<n;i++) if(g[i].size()==2 && is_2) return 0; vector<vector<int> > ans(n,vector<int> (n,0)); for(int i=0;i<n;i++) form_group(g[i],ans,is_2); build(ans); return 1; }

Compilation message (stderr)

supertrees.cpp: In function 'void form_group(std::vector<int>&, std::vector<std::vector<int> >&, bool)':
supertrees.cpp:26:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |   for(int i=1;i<g.size();i++)
      |               ~^~~~~~~~~
supertrees.cpp:31:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |  for(int i=0;i<g.size();i++){
      |              ~^~~~~~~~~
#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...