QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#420719 | #8720. BFS 序 0 | Kevin5307 | AC ✓ | 317ms | 41556kb | C++23 | 2.4kb | 2024-05-24 21:27:12 | 2024-05-24 21:27:19 |
Judging History
answer
//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
int n,p[300300],depth[300300];
int anc[19][300300],indeg[300300];
vector<int> G[300300];
inline pii lca(int u,int v)
{
for(int i=18;i>=0;i--)
{
if(depth[anc[i][u]]>=depth[v])
u=anc[i][u];
if(depth[anc[i][v]]>=depth[u])
v=anc[i][v];
}
for(int i=18;i>=0;i--)
if(anc[i][u]!=anc[i][v])
{
u=anc[i][u];
v=anc[i][v];
}
return mp(u,v);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n;
for(int i=2;i<=n;i++)
{
cin>>p[i];
anc[0][i]=p[i];
}
for(int i=1;i<=n;i++)
depth[i]=depth[p[i]]+1;
for(int i=1;i<19;i++)
for(int j=1;j<=n;j++)
anc[i][j]=anc[i-1][anc[i-1][j]];
int q;
cin>>q;
while(q--)
{
int m;
cin>>m;
vector<int> ord(m);
for(auto &x:ord)
cin>>x;
bool ok=true;
for(int i=1;i<m;i++)
if(depth[ord[i]]<depth[ord[i-1]])
ok=false;
for(int i=1;i<m;i++)
if(ord[i]==ord[i-1])
ok=false;
if(ok)
{
vector<int> pool;
for(int i=1;i<m;i++)
if(depth[ord[i]]==depth[ord[i-1]])
{
pii pr=lca(ord[i-1],ord[i]);
pool.pb(pr.first);
pool.pb(pr.second);
}
srt(pool);
uni(pool);
for(auto x:pool)
{
G[x].clear();
indeg[x]=0;
}
for(int i=1;i<m;i++)
if(depth[ord[i]]==depth[ord[i-1]])
{
pii pr=lca(ord[i-1],ord[i]);
G[pr.first].pb(pr.second);
indeg[pr.second]++;
}
queue<int> q;
for(auto x:pool)
if(!indeg[x])
q.push(x);
while(!q.empty())
{
int x=q.front();
q.pop();
for(auto y:G[x])
{
indeg[y]--;
if(!indeg[y])
q.push(y);
}
}
for(auto x:pool)
if(indeg[x])
ok=false;
}
if(ok)
cout<<"Yes\n";
else
cout<<"No\n";
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 28156kb
input:
6 1 1 3 2 4 10 4 3 6 2 5 1 4 3 2 4 5 5 2 5 4 6 3 3 1 4 2 3 5 6 3 5 4 5 2 6 1 4 4 3 2 5 4 4 6 2 3 3 3 2 6
output:
No Yes Yes No No No No No No Yes
result:
ok 10 token(s): yes count is 3, no count is 7
Test #2:
score: 0
Accepted
time: 317ms
memory: 41556kb
input:
300000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
output:
No Yes Yes Yes No No No No No No Yes Yes No Yes No Yes Yes Yes No No No No Yes No No Yes No No No No Yes Yes Yes No No Yes No No No No No No No Yes No Yes No Yes No No No No Yes Yes Yes No No Yes No No No No No Yes Yes No No No No No Yes Yes No Yes No No No Yes No No Yes No No Yes Yes Yes No No No Y...
result:
ok 254 token(s): yes count is 89, no count is 165
Test #3:
score: 0
Accepted
time: 300ms
memory: 41468kb
input:
300000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
output:
Yes No No Yes No No Yes Yes No Yes No Yes No No No Yes No No No No Yes No No No No No Yes Yes No No No Yes No No No No No Yes Yes Yes No No No No No No No Yes No Yes No No No Yes No No No Yes No No Yes No Yes Yes No No No Yes No Yes Yes Yes No Yes No Yes Yes Yes Yes Yes No Yes No No No No No Yes No ...
result:
ok 266 token(s): yes count is 102, no count is 164
Test #4:
score: 0
Accepted
time: 302ms
memory: 41548kb
input:
300000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
output:
No No Yes No Yes No No No No No No No No Yes No No No No No No No No Yes No No No No Yes No No No No No No No Yes Yes No No No No No No Yes No No No Yes Yes No No No Yes Yes No Yes No Yes No Yes No Yes No Yes No No Yes No No No No No No No Yes Yes No Yes No No No No No No Yes Yes No Yes Yes No No No...
result:
ok 252 token(s): yes count is 87, no count is 165
Test #5:
score: 0
Accepted
time: 4ms
memory: 26176kb
input:
10 1 1 3 3 1 3 1 3 9 10000 4 3 5 6 9 5 3 1 4 9 6 5 6 4 3 5 7 28 8 3 4 3 1 6 3 5 8 7 2 4 4 4 2 7 5 9 2 4 10 8 4 10 3 4 5 7 3 5 2 9 6 4 7 2 3 9 5 5 9 2 5 6 1 12 3 5 8 8 1 3 5 8 4 5 9 1 29 3 9 9 1 5 8 5 5 6 10 8 8 4 8 4 2 8 10 5 7 3 7 1 8 4 7 5 1 6 7 5 9 8 3 2 1 6 4 4 1 9 5 22 10 9 5 4 5 8 10 3 2 1 10 ...
output:
No No No No No No No No No No No No No No No No No No No No No No No No No No No Yes No No No No Yes No No No No No Yes No No No No No No No Yes No No No No Yes No No No Yes No No Yes No No No No No No No No No No No No No No No Yes No Yes No No No No No No No No No Yes Yes No Yes No No No No No No ...
result:
ok 10000 token(s): yes count is 1058, no count is 8942
Test #6:
score: 0
Accepted
time: 4ms
memory: 26152kb
input:
9 1 2 1 2 2 4 2 6 10000 6 5 1 4 3 7 8 14 6 8 7 9 7 5 1 8 3 6 3 8 5 2 2 6 9 17 7 8 6 5 2 1 5 5 9 3 4 1 5 2 7 2 5 3 8 6 5 5 3 9 1 6 8 8 3 5 8 7 9 4 6 2 4 8 9 6 5 7 4 7 2 9 3 8 1 6 1 4 9 5 6 2 4 7 5 4 3 5 9 5 2 1 3 4 4 5 7 3 3 9 1 8 4 4 2 8 6 26 7 4 7 6 1 7 9 4 5 5 8 9 8 2 4 8 9 6 2 8 6 4 5 5 4 4 45 3 ...
output:
No No Yes No Yes No No No No No No No No No Yes No No No No No No Yes No No No No No No Yes No No No No No No No No Yes Yes No No No Yes No No No No No No No No No No No No Yes No No No No No No No No No No No No No Yes No Yes No No No No No No No No Yes No No No Yes No No Yes No No No No No No No N...
result:
ok 10000 token(s): yes count is 1492, no count is 8508
Test #7:
score: 0
Accepted
time: 3ms
memory: 30296kb
input:
8 1 1 2 4 2 4 6 10000 5 2 6 6 2 1 3 7 3 8 2 8 1 5 7 5 1 2 7 3 2 3 5 3 8 4 3 5 8 2 4 5 3 4 3 2 1 8 6 6 8 4 5 3 1 6 3 1 2 7 4 6 4 8 6 4 3 5 4 7 6 8 5 11 2 1 6 5 2 7 1 3 3 5 4 4 6 1 7 2 7 6 2 7 8 4 1 3 3 4 6 7 3 7 1 6 38 3 4 6 6 3 4 8 1 5 3 1 8 8 6 2 3 6 7 8 8 4 2 3 7 3 3 6 7 7 5 7 5 8 8 5 4 5 7 1 8 5 ...
output:
No No No No Yes No No No No No No No No No No Yes No No Yes No No No No No Yes No Yes No No No Yes Yes No No No No No No Yes No No No No No No No No No No No Yes No No No No No No No No No Yes No No No No No No No No No No No No No No Yes No No No No No No No No No No No No No No Yes No No No No No ...
result:
ok 10000 token(s): yes count is 1568, no count is 8432
Test #8:
score: 0
Accepted
time: 3ms
memory: 26180kb
input:
7 1 2 3 1 2 5 10000 5 1 7 3 5 6 5 5 3 2 7 4 4 5 2 6 4 12 3 1 5 5 6 6 3 5 3 5 3 3 11 2 3 2 6 7 3 6 6 3 3 3 2 3 2 6 1 3 4 2 6 7 3 2 7 1 6 5 2 7 3 4 1 27 2 5 6 1 7 1 7 1 4 6 7 1 6 2 1 7 1 3 4 4 7 7 2 6 4 4 3 2 5 6 1 7 3 3 1 4 4 1 7 3 4 3 4 2 1 4 4 1 6 7 4 6 2 7 4 4 5 1 6 4 1 3 5 1 2 3 5 7 5 2 3 7 6 5 1...
output:
No No Yes No No No No No No No Yes Yes No Yes No No No No Yes No No No No Yes No No Yes No No No No No No No No No No No No No No No No No No No No No No No Yes No No Yes No Yes Yes No Yes Yes No No No No No No No No No No Yes No No No No No No No No Yes No Yes No No No No Yes Yes Yes Yes Yes Yes Ye...
result:
ok 10000 token(s): yes count is 2205, no count is 7795
Extra Test:
score: 0
Extra Test Passed