Submission #302112

#TimeUsernameProblemLanguageResultExecution timeMemory
302112aymane7Connecting Supertrees (IOI20_supertrees)C++17
0 / 100
1 ms512 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(auto x:co[i]) for(auto y:co[i]){ if(x==y) continue; if(b[x][y]==0) return 0; ans[x][y]=1,ans[y][x]=1; } if(sz(co[i])>2) ans[co[i][0]][co[i].back()]=0,ans[co[i].back()][co[i][0]]=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...