제출 #302166

#제출 시각아이디문제언어결과실행 시간메모리
302166aymane7슈퍼트리 잇기 (IOI20_supertrees)C++17
11 / 100
246 ms22264 KiB
#include<bits/stdc++.h> #include"supertrees.h" #pragma GCC optimize("O2") #define S second #define F first #define PB push_back #define sz(x) (int) x.size() #define all(x) x.begin(),x.end() #define L(x) 2*x #define R(x) 2*x+1 #define M(x,y) (x+y)/2 using namespace std; typedef long long ll; const int N=1e3+1; int p[N],lvl[N]; int getp(int x){ return (p[x]==x)? x : p[x]=getp(p[x]); } void unite(int x,int y){ if(getp(x)==getp(y)) return ; if(lvl[x]>lvl[y]) swap(x,y); p[x]=y; if(lvl[x]==lvl[y]) lvl[y]++; } /* void build(vector<vector<int>> t){ for(auto v:t){ for(auto x:v) cout<<x<<" "; cout<<endl; } } */ int construct(vector<vector<int>> b){ int n=sz(b); vector<vector<int>> ans(n,vector<int>(n,0)); for(int i=0;i<n;i++){ lvl[i]=0; p[i]=i; } for(int i=0;i<n;i++) for(int j=0;j<n;j++) if(b[i][j]) unite(i,j); vector<int> co[n]; for(int i=0;i<n;i++) co[getp(i)].PB(i); for(int i=0;i<n;i++){ if(sz(co[i])<=1) continue; for(int j=0;j<sz(co[i])-1;j++) ans[co[i][j]][co[i][j+1]]=1,ans[co[i][j+1]][co[i][j]]=1; for(auto x:co[i]) for(auto y:co[i]){ if(x==y) continue; if(b[x][y]==0) return 0; } } build(ans); return 1; } /* int main(){ int n; cin>>n; vector<vector<int>> t(n,vector<int>(n,0)); for(int i=0;i<n;i++) for(int j=0;j<n;j++) cin>>t[i][j]; construct(t); } */
#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...