제출 #527805

#제출 시각아이디문제언어결과실행 시간메모리
527805Servus2022슈퍼트리 잇기 (IOI20_supertrees)C++14
21 / 100
197 ms29124 KiB
#include "supertrees.h" #include <bits/stdc++.h> using namespace std; const int NMAX = 1e3 + 1; int N; int P[NMAX][NMAX]; int head[NMAX]; bool Edge[NMAX][NMAX]; class DisjointSets { int T[NMAX], Size[NMAX]; private: inline int Find (int X) { if(X == T[X]) return X; return (T[X] = Find(T[X])); } inline void my_swap (int &x, int &y) { x = (x ^ y), y = (x ^ y), x = (x ^ y); return; } public: inline void Initialize (int N) { for(int i = 1; i <= N; ++i) T[i] = i, Size[i] = 1; return; } inline bool Unify (int X, int Y) { X = Find(X), Y = Find(Y); if(X == Y) return 0; if(Size[X] < Size[Y]) my_swap(X, Y); Size[X] += Size[Y], Size[Y] = 0; T[Y] = X; return 1; } inline int Who_is_the_boss (int Node) { return Find(Node); } } DSU; void Build_type_1 () { DSU.Initialize(N); for(int i = 1; i <= N; ++i) for(int j = 1; j <= N; ++j) if(P[i][j] == 1) DSU.Unify(i, j); for(int i = 1; i <= N; ++i) head[i] = DSU.Who_is_the_boss(i); return; } int construct (vector < vector < int > > p) { N = (int)p.size(); for(int i = 0; i < N; ++i) for(int j = 0; j < N; ++j) P[i + 1][j + 1] = p[i][j]; Build_type_1(); for(int i = 1; i <= N; ++i) for(int j = 1; j <= N; ++j) if(P[i][j] == 0 && head[i] == head[j]) return 0; for(int i = 1; i <= N; ++i) if(i != head[i]) Edge[i][head[i]] = Edge[head[i]][i] = 1; vector < vector < int > > ans; for(int i = 0; i < N; ++i) { vector < int > _temp; for(int j = 0; j < N; ++j) if(Edge[i + 1][j + 1]) _temp.push_back(1); else _temp.push_back(0); ans.push_back(_temp); } build(ans); 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...