# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
64778 | kjp4155 | 족보 (KOI18_family) | C++17 | 20 ms | 14456 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <vector>
using namespace std;
typedef pair<int,int> Pi;
int N[2],K;
vector<int> E[2][300500];
int pa[2][300500], root[2];
bool vis[2][300500];
vector<Pi> v[2];
Pi dfs(int k, int x){
if( 1 <= x && x <= K ) return {x,x};
int mx = -1, mn = 1e9;
for(auto e : E[k][x]){
Pi res = dfs(k, e);
mx = max(mx, res.second);
mn = min(mn, res.first);
}
v[k].push_back({mn,mx});
return {mn, mx};
}
int main(){
scanf("%d%d%d",&N[0],&N[1],&K);
for(int k=0;k<2;k++){
for(int i=1;i<=N[k];i++){
scanf("%d",&pa[k][i]);
if( pa[k][i] == 0 ) root[k] = i;
}
}
// make tree
for(int k=0;k<2;k++){
for(int i=1;i<=K;i++){
int cur = i;
while( !vis[k][cur] && pa[k][cur] != 0 ){
vis[k][cur] = true;
E[k][pa[k][cur]].push_back(cur);
cur = pa[k][cur];
}
}
}
dfs(0,root[0]); dfs(1,root[1]);
// for(auto e : v[0]) printf("%d-%d\n",e.first,e.second);
// printf("\n");
// for(auto e : v[0]) printf("%d-%d\n",e.first,e.second);
for(auto a : v[0]){
for(auto b : v[1]){
if( a.second < b.first ) continue;
if( b.second < a.first ) continue;
if( a.first <= b.first && b.second <= a.second ) continue;
if( b.first <= a.first && a.second <= b.second ) continue;
printf("NO\n");
return 0;
}
}
printf("YES\n");
}
컴파일 시 표준 에러 (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... |