제출 #309380

#제출 시각아이디문제언어결과실행 시간메모리
309380georgerapeanu슈퍼트리 잇기 (IOI20_supertrees)C++17
0 / 100
1 ms256 KiB
#include "supertrees.h" #include <vector> using namespace std; struct dsu_t{ int n; int father[1005]; dsu_t(int n){ this->n = n; for(int i = 0;i < n;i++){ father[i] = -1; } } int find_root(int nod){ if(father[nod] == -1){ return nod; } return father[nod] = find_root(father[nod]); } bool unite(int x,int y){ x = find_root(x); y = find_root(y); if(x == y){ return false; } father[x] = y; return true; } }; int construct(vector<vector<int>> p) { int n = p.size(); vector<vector<int>> answer(n,vector<int>(n,0)); dsu_t dsu(n); for (int i = 0; i < n; i++) { for(int j = 0;j < n;j++){ if(p[i][j] == 3){ return 0; } else if(p[i][j] == 1){ if(dsu.unite(i,j)){ answer[i][j] = answer[j][i] = 1; } } } } for (int i = 0; i < n; i++) { for(int j = 0;j < n;j++){ if(p[i][j] == 2){ if(dsu.find_root(i) == dsu.find_root(j)){ return 0; } } } } vector<int> roots; for(int i = 0;i < n;i++){ if(dsu.find_root(i) == i){ roots.push_back(i); } } if(roots.size() == 2){ return 0; } for(int i = 0;i < (int)roots.size();i++){ answer[roots[i]][roots[(i + 1) % roots.size()]] = 1; answer[roots[(i + 1) % roots.size()]][roots[i]] = 1; } build(answer); 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...