# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
557523 |
2022-05-05T12:27:04 Z |
myrcella |
None (KOI18_family) |
C++17 |
|
26 ms |
44932 KB |
//by szh
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl
#define pq priority_queue
#define inf 0x3f
#define rep(i,a,b) for (int i=a;i<(b);i++)
#define MP make_pair
#define SZ(x) (int(x.size()))
#define ll long long
#define mod 1000000007
#define ALL(x) x.begin(),x.end()
void inc(int &a,int b) {a=(a+b)%mod;}
void dec(int &a,int b) {a=(a-b+mod)%mod;}
int lowbit(int x) {return x&(-x);}
ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;}
const int maxn = 3e5+10;
int n[2],m;
int fa[2][maxn];
map <int,int> mp[2][maxn];
int sz[2][maxn];
vector <int> edge[2][maxn];
int dep[2][maxn];
vector <pii> pt;
int getf(int id,int node) {
if (fa[id][node]==node) return fa[id][node];
else return fa[id][node] = getf(id,fa[id][node]);
}
int p[2][maxn];
int dfs(int id,int u) {
if (u<m) return 1;
sz[id][u]=0;
pt.pb({id,u});
for (int v:edge[id][u]) {
dep[id][v]= dep[id][u]+1;
sz[id][u]+=dfs(id,v);
}
return sz[id][u];
}
bool cmp(pii a, pii b ) {
if (sz[a.fi][a.se]!=sz[b.fi][b.se]) return sz[a.fi][a.se]<sz[b.fi][b.se];
else return dep[a.fi][a.se]>dep[b.fi][b.se];
}
int main() {
// freopen("input.txt","r",stdin);
std::ios::sync_with_stdio(false);cin.tie();
cin>>n[0]>>n[1]>>m;
memset(sz,0,sizeof(sz));
int rt[2];
rep(k,0,2) rep(i,0,n[k]) {
cin>>p[k][i];
p[k][i]--;
if (p[k][i]!=-1) edge[k][p[k][i]].pb(i);
else rt[k] = i;
if (i<m) fa[k][i] = p[k][i];
else fa[k][i] = i;
}
dfs(0,rt[0]);
dfs(1,rt[1]);
sort(ALL(pt));
rep(k,0,2)
rep(i,0,m) {
int ff1 = getf(k,i);
int ff2 = getf(1-k,i);
mp[k][ff1][ff2] = 1;
}
sort(ALL(pt),cmp);
for (auto cur:pt) {
int x=cur.fi,y=cur.se;
int tmp = getf(1-x,(mp[x][y].begin())->fi);
if (mp[x][y].size()>1) {
for (auto it:mp[x][y]) {
if (getf(1-x,it.fi)!=tmp) {
cout<<"NO";
return 0;
}
}
}
// debug(tmp);
if (p[x][y]!=-1) mp[x][y][tmp] = 1, fa[x][y] = p[x][y];
}
cout<<"YES";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
44884 KB |
Output is correct |
2 |
Correct |
23 ms |
44932 KB |
Output is correct |
3 |
Correct |
25 ms |
44928 KB |
Output is correct |
4 |
Correct |
26 ms |
44892 KB |
Output is correct |
5 |
Incorrect |
23 ms |
44864 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
44884 KB |
Output is correct |
2 |
Correct |
23 ms |
44932 KB |
Output is correct |
3 |
Correct |
25 ms |
44928 KB |
Output is correct |
4 |
Correct |
26 ms |
44892 KB |
Output is correct |
5 |
Incorrect |
23 ms |
44864 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
44884 KB |
Output is correct |
2 |
Correct |
23 ms |
44932 KB |
Output is correct |
3 |
Correct |
25 ms |
44928 KB |
Output is correct |
4 |
Correct |
26 ms |
44892 KB |
Output is correct |
5 |
Incorrect |
23 ms |
44864 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
44884 KB |
Output is correct |
2 |
Correct |
23 ms |
44932 KB |
Output is correct |
3 |
Correct |
25 ms |
44928 KB |
Output is correct |
4 |
Correct |
26 ms |
44892 KB |
Output is correct |
5 |
Incorrect |
23 ms |
44864 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |