제출 #431223

#제출 시각아이디문제언어결과실행 시간메모리
431223MOUF_MAHMALAT슈퍼트리 잇기 (IOI20_supertrees)C++14
0 / 100
1 ms216 KiB
#include "supertrees.h" #include<bits/stdc++.h> using namespace std; typedef int ll; vector<vector<ll> >v; vector<pair<ll,ll> >op; ll n,p[1009],sz[1009]; bool b[1009]; ll gp(ll z) { if(p[z]==z) return z; return p[z]=gp(p[z]); } void mrg(ll x,ll y) { if(sz[y]>sz[x]) swap(x,y); p[y]=x; sz[x]+=sz[y]; } int construct(vector<vector<int> > pp) { n=pp.size(); v.resize(n); for(ll i=0; i<n; i++) v[i].resize(n); for(ll i=0; i<n; i++) p[i]=i,sz[i]=1; for(ll i=0; i<n; i++) for(ll j=0; j<n; j++) { if(i==j||pp[i][j]==0) continue; ll x=gp(i),y=gp(j); if(x==y) continue; mrg(x,y); op.push_back({x,y}); } for(ll i=0; i<n; i++) for(ll j=0; j<n; j++) { if(pp[i][j]==0||p[i]==i) continue; ll x=gp(i); if(b[x]==1) continue; if(sz[x]<=2) return 0; op.push_back({i,x}); b[x]=1; } for(ll i=0; i<n; i++) for(ll j=0; j<n; j++) { if(pp[i][j]) continue; ll x=gp(i),y=gp(j); if(x==y) return 0; } for(auto z:op) v[z.first][z.second]=v[z.second][z.first]=1; build(v); 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...