제출 #319760

#제출 시각아이디문제언어결과실행 시간메모리
319760NicolaAbusaad2014슈퍼트리 잇기 (IOI20_supertrees)C++14
0 / 100
266 ms22116 KiB
#include "supertrees.h" #include <bits/stdc++.h> using namespace std; vector<long>parent; std::vector<std::vector<int> > answer; long find_set(long x) { if(parent[x]==x){ return x; } long z=find_set(parent[x]); parent[x]=z; return z; } void union_set(long x,long z) { x=find_set(x); z=find_set(z); if(x!=z){ parent[z]=x; } } int construct(std::vector<std::vector<int> > p) { int n = p.size(); for(long i=0;i<n;i++){ parent.push_back(i); } for (int i = 0; i < n; i++) { std::vector<int> row; row.resize(n); answer.push_back(row); } bool ok=true; for(long i=0;i<n;i++){ for(long j=i+1;j<n;j++){ if(p[i][j]==2){ union_set(i,j); } } } for(long i=0;i<n;i++){ for(long j=i+1;j<n;j++){ if(p[i][j]==0){ if(find_set(i)==find_set(j)){ ok=false; i=n; break; } } } } vector<vector<long> >v(n); long x,z; for(long i=0;i<n;i++){ x=find_set(i); v[x].push_back(i); } for(long i=0;i<n;i++){ x=v[i].size(); if(x>2){ for(long j=0;j<x;j++){ z=v[i][(j+1)%x]; answer[v[i][z]][v[i][j]]=1; answer[v[i][j]][v[i][z]]=1; } } else if(x==2){ ok=false; break; } } if(ok){ build(answer); return 1; } return 0; }
#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...