# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|
403606 | | lyc | 족보 (KOI18_family) | C++14 | | 600 ms | 196940 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) cerr << #x << " :: " << x << endl
#define _ << " " <<
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for (int i=(a);i>=(b);--i)
//const int mxN = 3e5+5;
//const int mxK = 3e5+5;
const int mxN = 5005;
const int mxK = 5005;
const int inf = 1e9+5;
int K;
struct Tree {
int N;
vector<int> g[mxN];
int pa[mxN];
int dep[mxN];
int _lca[mxK][mxK];
void read() {
FOR(i,1,N){
int P; cin >> P;
g[P].push_back(i);
}
}
void dfs(int u) {
for (int& v : g[u]) {
pa[v] = u;
dep[v] = dep[u]+1;
dfs(v);
}
}
int lca(int a, int b) {
if (_lca[a][b] != -1) return _lca[a][b];
if (a == b) return a;
if (dep[a] > dep[b]) {
return _lca[a][b] = lca(pa[a],b);
} else {
return _lca[a][b] = lca(a,pa[b]);
}
}
void run() {
memset(pa,-1,sizeof pa);
dep[0] = 0;
dfs(0);
memset(_lca,-1,sizeof _lca);
}
inline int lcd(int a, int b) {
return dep[lca(a,b)];
}
} A, B;
int mn[mxN];
int main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> A.N >> B.N >> K;
A.read();
B.read();
A.run();
B.run();
bool die = 0;
FOR(i,1,K){
FOR(j,1,A.N) mn[j] = inf;
FOR(j,1,K) if (j != i) {
int a = A.lcd(i,j), b = B.lcd(i,j);
mn[a] = min(mn[a],b);
}
RFOR(j,A.N-1,1) mn[j] = min(mn[j+1],mn[j]);
FOR(j,1,K) if (j != i) {
int a = A.lcd(i,j), b = B.lcd(i,j);
if (a < A.N) die |= b > mn[a+1];
}
}
cout << (die ? "NO" : "YES") << '\n';
}
# | 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... |