제출 #434669

#제출 시각아이디문제언어결과실행 시간메모리
434669pere_gil슈퍼트리 잇기 (IOI20_supertrees)C++14
0 / 100
1 ms204 KiB
#include "supertrees.h" #include "bits/stdc++.h" using namespace std; #define vvi vector<vector<int> > bool semamo=false; void pri_graph(vvi &v){ for(int i=0;i<v.size();i++) for(int j=i;j<v.size();j++) if(v[i][j]) printf("%d <-> %d\n",i,j); printf("\n"); } void init(int n, vector<int> &p){ for(int i=0;i<n;i++) p[i]=i; } int find_set(int n, vector<int> &p){ return (n==p[n]) ? n : p[n]=find_set(p[n],p); } bool same_set(int a, int b, vector<int> &p){ return find_set(a,p)==find_set(b,p); } void union_set(int a, int b, vector<int> &p){ if(!same_set(a,b,p)) p[find_set(a,p)]=find_set(b,p); } vector<int> to_vector(unordered_set<int> &s){ unordered_set<int> :: iterator it; vector<int> v; for(it=s.begin();it!=s.end();it++) v.push_back(*it); return v; } void join_1(vector<int> &g, vvi &res){ for(int i=1;i<g.size();i++) res[g[i-1]][g[i]]=res[g[i]][g[i-1]]=1; } void join_2(vector<int> &g, vvi &res){ if(g.size()<3) semamo=true; for(int i=0;i<g.size();i++){ int j=(i+1)%g.size(); res[g[i]][g[j]]=res[g[j]][g[i]]=1; } } void make_group(int n, vector<int> &g, vvi &v, vvi &res){ vector<int> p(n); init(n,p); unordered_set<int> mid; for(int i=0;i<g.size();i++){ int aux=0; for(int j=0;j<g.size();j++) if(v[g[i]][g[j]]==1) union_set(g[i],g[j],p); else aux++; if(aux==g.size()-1) mid.insert(g[i]); } vvi one(n); for(int i=0;i<g.size();i++){ if(mid.find(g[i])==mid.end()) one[find_set(g[i],p)].push_back(g[i]); if(g[i]==find_set(g[i],p)) mid.insert(g[i]); } vector<int> v_mid=to_vector(mid); /* printf("The middle: "); for(int i=0;i<v_mid.size();i++) printf("%d ",v_mid[i]); printf("\nGroup of one\n"); for(int i=0;i<n;i++){ if(!one[i].size()) continue; for(int j=0;j<one[i].size();j++) printf("%d ",one[i][j]); printf("\n"); } */ join_2(v_mid,res); for(int i=0;i<n;i++) if(one[i].size()) join_1(one[i],res); } int construct(vvi v){ int n=v.size(); vector<int> p(n); init(n,p); for(int i=0;i<n;i++) for(int j=0;j<n;j++) if(v[i][j]) union_set(i,j,p); vvi g(n); for(int i=0;i<n;i++) g[find_set(i,p)].push_back(i); for(int i=0;i<n;i++) for(int j=0;j<n;j++) if(same_set(i,j,p) && v[i][j]==0) return 0; vvi res(n,vector<int> (n,0)); for(int i=0;i<n;i++) if(g[i].size()>0) make_group(n,g[i],v,res); if(semamo) return 0; //pri_graph(res); build(res); return 1; }

컴파일 시 표준 에러 (stderr) 메시지

supertrees.cpp: In function 'void pri_graph(std::vector<std::vector<int> >&)':
supertrees.cpp:10:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |  for(int i=0;i<v.size();i++)
      |              ~^~~~~~~~~
supertrees.cpp:11:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |   for(int j=i;j<v.size();j++)
      |               ~^~~~~~~~~
supertrees.cpp: In function 'void join_1(std::vector<int>&, std::vector<std::vector<int> >&)':
supertrees.cpp:41:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |  for(int i=1;i<g.size();i++)
      |              ~^~~~~~~~~
supertrees.cpp: In function 'void join_2(std::vector<int>&, std::vector<std::vector<int> >&)':
supertrees.cpp:47:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |  for(int i=0;i<g.size();i++){
      |              ~^~~~~~~~~
supertrees.cpp: In function 'void make_group(int, std::vector<int>&, std::vector<std::vector<int> >&, std::vector<std::vector<int> >&)':
supertrees.cpp:58:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |  for(int i=0;i<g.size();i++){
      |              ~^~~~~~~~~
supertrees.cpp:60:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |   for(int j=0;j<g.size();j++)
      |               ~^~~~~~~~~
supertrees.cpp:63:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |   if(aux==g.size()-1) mid.insert(g[i]);
      |      ~~~^~~~~~~~~~~~
supertrees.cpp:66:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |  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...