Submission #429334

#TimeUsernameProblemLanguageResultExecution timeMemory
429334pere_gilConnecting Supertrees (IOI20_supertrees)C++14
0 / 100
1 ms204 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(!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); /* printf("Groups are:\n"); for(int i=0;i<n;i++){ if(g[i].size()==0) continue; printf("%d: ",i); for(int j=0;j<g[i].size();j++) printf("%d ",g[i][j]); printf("\n"); } */ 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; for(int i=0;i<n;i++) if(g[i].size()==2) return 0; bool is_2=false; for(int i=0;i<n;i++) for(int j=0;j<n;j++) is_2=v[i][j]==2; 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:25:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |   for(int i=1;i<g.size();i++)
      |               ~^~~~~~~~~
supertrees.cpp:30:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |  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...