# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
130369 | red1108 | 족보 (KOI18_family) | C++17 | 15 ms | 14456 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
vector<int> tree[2][300010];
int par[300010], n1, n2, p, root1, root2;
int tsize[2][300010], sth[2][300010], siz[300010];
priority_queue<pair<int,pair<int,int>>> pq;
void dfs(int t, int x){
if(x<=p) tsize[t][x]=1;
if(x<=p) sth[t][x]=x;
for(auto i:tree[t][x]){
dfs(t, i);
tsize[t][x]+=tsize[t][i];
if(sth[t][i]<=p) sth[t][x]=sth[t][i];
}
}
int findpar(int x){
if(x==par[x]) return x;
return par[x]=findpar(par[x]);
}
void hap(int x, int y){
if(findpar(x)==findpar(y)) return ;
siz[findpar(y)]+=siz[findpar(x)];
par[findpar(x)]=findpar(y);
}
int main(){
int i;
scanf("%d %d %d", &n1, &n2, &p);
for(i=1;i<=n1;i++){
int a;
scanf("%d", &a);
tree[0][a].push_back(i);
if(a==0) root1=i;
}
for(i=1;i<=n2;i++){
int a;
scanf("%d", &a);
tree[1][a].push_back(i);
if(a==0) root2=i;
}
for(i=1;i<=p;i++) {
par[i]=i;
siz[i]=1;
}
dfs(0,root1);
dfs(1,root2);
for(i=p+1;i<=n1;i++)
pq.push(make_pair(-tsize[0][i],make_pair(0,i)));
for(i=p+1;i<=n2;i++)
pq.push(make_pair(-tsize[1][i],make_pair(1,i)));
while(!pq.empty()){
int x = pq.top().second.second;
int t = pq.top().second.first;
pq.pop();
int fi=sth[t][tree[t][x][0]];
for(auto i:tree[t][x]){
hap(fi,sth[t][i]);
}
if(siz[findpar(fi)]!=tsize[t][x]){
printf("NO");
return 0;
}
//printf("(%d %d) = %d \n", t, x, tsize[t][x]);
}
printf("YES");
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |