제출 #431406

#제출 시각아이디문제언어결과실행 시간메모리
431406Rouge_Hugo슈퍼트리 잇기 (IOI20_supertrees)C++14
96 / 100
312 ms26108 KiB
#include<bits/stdc++.h> #include "supertrees.h" #include <vector> #define fi first #define se second #define pb push_back using namespace std; int n;const int N=1009; vector<vector<int>>ans; int pa[N],nw[N],s=0,sz[N],p[N][N],vis[N]; vector<int>v[N];vector<int>sta; vector<int>u; void merge(int x,int y) { x=pa[x];y=pa[y]; if(x==y)return; if(sz[x]<sz[y])swap(x,y); for(auto it:v[y]) { sz[x]++; v[x].pb(it); pa[it]=x; } }vector<int>h; int go(int x,int y) { h.clear(); sta.clear();int last=x;h.pb(x); for(auto it:v[x])sta.pb(it); nw[x]=++s;int three=0; for(int j=y+1;j<u.size();j++) { int i=u[j]; if(vis[i])continue; int r=1,re=0; for(auto it:v[i]) { for(auto pp:sta) { if(p[it][pp]==3)three++; if(p[it][pp]!=2)r=0; } } if(r==0)continue; vis[i]=1;nw[i]=s;h.pb(i); for(auto it:v[i])sta.pb(it); ans[last][i]=1; ans[i][last]=1; last=i; } if(ans[x][last])return 0; if(x==last)return 1; long long al=u.size();al*=al; if(three>0&&three!=al)return 0; if(three&&h.size()<4)return 0; if(three){ans[h[1]][h[3]]=1; ans[h[3]][h[1]]=1;} ans[x][last]=1; ans[last][x]=1; return 1; } vector<int>w; int construct(vector<vector<int>> P) { n = P.size(); for(int i=0;i<n;i++) { pa[i]=i;sz[i]=1;v[i].pb(i); } for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(i==j)continue; p[i][j]=P[i][j]; if(p[i][j]==1)merge(i,j); } } for(int i=0;i<n;i++)w.pb(0); for(int i=0;i<n;i++) { ans.pb(w); } for(int i=0;i<n;i++) { if(pa[i]!=i)continue; for(auto it:v[i]) { if(it==i)continue; ans[i][it]=1; ans[it][i]=1; } for(auto it:v[i]) { for(auto pp:v[i]) { if(it==pp)continue; if(p[it][pp]!=1)return 0; } } u.pb(i); } for(int i=0;i<u.size();i++) { int it=u[i]; if(vis[it])continue; vis[it]=1; int z=go(it,i); if(z==0)return 0; } for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(i==j)continue; int x=nw[pa[i]],y=nw[pa[j]]; if(x!=y&&p[i][j]==2)return 0; } } build(ans);return 1; }

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

supertrees.cpp: In function 'int go(int, int)':
supertrees.cpp:31:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |     for(int j=y+1;j<u.size();j++)
      |                   ~^~~~~~~~~
supertrees.cpp:35:17: warning: unused variable 're' [-Wunused-variable]
   35 |         int r=1,re=0;
      |                 ^~
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:102:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  102 |     for(int i=0;i<u.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...