제출 #1117960

#제출 시각아이디문제언어결과실행 시간메모리
1117960I_FloPPed21슈퍼트리 잇기 (IOI20_supertrees)C++17
0 / 100
1 ms336 KiB
#include "supertrees.h" #include <iostream> #include <vector> using namespace std; const int N=1001; vector<vector<int>>b; int n,componente[N],cnt,root[N],modes[N][N]; bool viz[N]; void fa_dfs(int i) { viz[i]=true; componente[i]=cnt; for(int j=0; j<n; j++) { if(viz[j]==true) continue; if(modes[i][j]==1) { b[i][j]=1; b[j][i]=1; fa_dfs(j); } } } bool e_root[N]; vector<int>adj[N]; bool viz2[N]; bool nah=false; int comp=0,where[N]; void fa_dfs2(int nod) { adj[comp].push_back(nod); viz2[nod]=true; where[nod]=comp; for(int j=0; j<n; j++) { if(viz2[j]==true) continue; if(e_root[j]==false) continue; if(modes[nod][j]==2) { b[nod][j]=1; b[j][nod]=1; fa_dfs2(j); } } } int construct(vector<vector<int>>p) { n=p.size(); b.resize(n); for(int i=0; i<n; i++) b[i].resize(n); for(int i=0; i<n; i++) for(int j=0; j<n; j++) { modes[i][j]=p[i][j]; if(modes[i][j]==3) { return 0; } } for(int i=0; i<n; i++) { if(viz[i]==false) { cnt++; viz[i]=true; e_root[i]=true; componente[i]=cnt; fa_dfs(i); } } for(int i=0; i<n; i++) { if(e_root[i]&&viz2[i]==false) { comp++; fa_dfs2(i); } } for(int i=1;i<=comp;i++) { if(adj[i].size()==2) nah=true; if(adj[i].size()>2) { b[adj[i].back()][adj[i][0]]=1; b[adj[i][0]][adj[i].back()]=1; } } for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(modes[i][j]!=modes[j][i]) { nah=true; } if(modes[i][j]==0&&(componente[i]==componente[j]||where[i]==where[j])) nah=true; if(modes[i][j]==1&&componente[i]!=componente[j]) nah=true; if(modes[i][j]==1&&where[i]==where[j]) nah=true; if(modes[i][j]==2&&componente[i]==componente[j]) nah=true; if(modes[i][j]==2&&where[i]!=where[j]) nah=true; } } if(nah==true) return 0; build(b); return 1; }
#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...