# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
403308 |
2021-05-13T02:55:54 Z |
oolimry |
None (KOI18_family) |
C++17 |
|
8 ms |
14412 KB |
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef pair<int,int> ii;
int n1, n2, K;
vector<int> child[2][300005];
int num[2][300005];
int rep[2][300005];
struct check{ int num, u, t; };
vector<check> stuff;
void dfs(int t, int u){
if(u != 0 && u <= K){
num[t][u] = 1;
rep[t][u] = u;
}
else{
for(int v : child[t][u]){
dfs(t, v);
num[t][u] += num[t][v];
rep[t][u] = rep[t][v];
}
if(num[t][u] > 1) stuff.push_back({num[t][u], u, t});
///idk why child[t][u].size() > 1 is needed .-.
}
}
int p[300005];
int sz[300005];
int findSet(int u){
if(p[u] == u) return u;
else return p[u] = findSet(p[u]);
}
void unionSet(int u, int v){
u = findSet(u), v = findSet(v);
if(u == v) return;
if(u&1) swap(u,v);
p[u] = v;
sz[v] += sz[u];
}
int getSz(int u){
return sz[findSet(u)];
}
int main(){
//freopen("i.txt","r",stdin);
cin >> n1 >> n2 >> K;
for(int i = 1;i <= n1;i++){
int a; cin >> a;
child[0][a].push_back(i);
}
for(int i = 1;i <= n2;i++){
int a; cin >> a;
child[1][a].push_back(i);
}
dfs(0, 0); dfs(1, 0);
for(int i = 1;i <= K;i++){
p[i] = i;
sz[i] = 1;
}
sort(all(stuff), [&](check a, check b){
if(a.u == b.u) return a.num < b.num;
else return a.u < b.u;
});
for(check C : stuff){
for(int v : child[C.t][C.u]){
unionSet(rep[C.t][C.u], rep[C.t][v]);
}
if(getSz(rep[C.t][C.u]) != C.num){
cout << "NO";
return 0;
}
}
cout << "YES";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
14412 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
14412 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
14412 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
14412 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |