# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
915389 | 2024-01-23T19:29:18 Z | chirathnirodha | 슈퍼트리 잇기 (IOI20_supertrees) | C++17 | 0 ms | 0 KB |
#include "supertrees.h" #include <vector> using namespace std; #define F first #define S sedond #define PB push_back #define MP make_pair #define P push #define I insert typedef long long ll; typedef long l; typedef unsigned long long ull; int uni[1000]; int fin(int x){ if(uni[x]==x)return x; else return fin(uni[x]); } void merg(int x,int y){ x=fin(x); y=fin(y); if(x<y)uni[y]=x; else uni[x]=y; } int construct(vector<vector<int>> p) { int n = p.size(); vector<int> answer[n]; for(int i=0;i<n;i++)for(int j=0;j<n;j++)answer[i].PB(0); for(int i=0;i<n;i++)uni[i]=i; for(int i=0;i<n;i++)for(int j=0;j<n;j++)if(p[i][j]==3)return 0; vector<int> v1[n],v2[n]; for(int i=0;i<n;i++){ for(int j=i+1;j<n;j++){ if(p[i][j]==1 && fin(i)!=fin(j)){ answer[i][j]=answer[j][i]=1; merg(i,j); } } } for(int i=0;i<n;i++)for(int j=i+1;j<n;j++)if(p[i][j]!=1 && fin(i)==fin(j))return 0; for(int i=0;i<n;i++){ int comsiz=1; for(int j=i+1;j<n;j++){ if(p[i][j]==2 && fin(i)!=fin(j)){ answer[i][j]=answer[j][i]=1; merg(i,j); comsiz++; } } if(comsiz==2)return 0; } for(int i=0;i<n;i++)for(int j=i+1;j<n;j++)if(p[i][j]!=1 && fin(i)==fin(j))return 0; build(answer); return 1; }