Submission #557392

#TimeUsernameProblemLanguageResultExecution timeMemory
557392myrcella족보 (KOI18_family)C++17
0 / 100
18 ms33124 KiB
//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]; 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 in[2][maxn]; pq <pair<int,pii>, vector<pair<int,pii>>, greater <pair<int,pii>>> q; 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)); rep(k,0,2) rep(i,0,n[k]) { cin>>p[k][i]; p[k][i]--; if (i<m) { fa[k][i] = p[k][i]; sz[k][p[k][i]]++; } else fa[k][i] = i; } memset(in,false,sizeof(in)); rep(k,0,2) rep(i,0,m) { int ff1 = getf(k,i); if (!in[k][ff1]) { q.push(MP(sz[k][ff1],MP(k,ff1))); in[k][ff1] = true; } int ff2 = getf(1-k,i); mp[k][ff1][ff2] = 1; } while (!q.empty()) { auto cur = q.top(); q.pop(); if (sz[cur.se.fi][cur.se.se] != cur.fi) continue; int tmp = getf(1-cur.se.fi,(mp[cur.se.fi][cur.se.se].begin())->fi); if (mp[cur.se.fi][cur.se.se].size()>1) { for (auto it:mp[cur.se.fi][cur.se.se]) { if (getf(1-cur.se.fi,it.fi)!=tmp) { cout<<"NO"; return 0; } } if (cur.se.se==1) continue; sz[cur.se.fi][p[cur.se.fi][cur.se.se]] += cur.fi; mp[cur.se.fi][p[cur.se.fi][cur.se.se]][tmp] = 1; q.push(MP(sz[cur.se.fi][p[cur.se.fi][cur.se.se]],MP(cur.se.fi,p[cur.se.fi][cur.se.se]))); } } cout<<"YES"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...