QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#417092 | #8720. BFS 序 0 | ucup_team_qiuly# | AC ✓ | 173ms | 74564kb | C++17 | 1.6kb | 2024-05-22 14:14:42 | 2024-05-22 14:14:44 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
const int N=5e5+5;
int n,m,c,a[N],dep[N],dg[N],vs[N],fa[N][20];
vector<int> o,e[N],e1[N];queue<int> q;
void dfs(int u,int f)
{
fa[u][0]=f;for(int i=1;i<=19;++i) fa[u][i]=fa[fa[u][i-1]][i-1];
dep[u]=dep[f]+1;for(auto v:e[u]) if(v!=f) dfs(v,u);
}
int lca(int u,int v)
{
if(dep[u]<dep[v]) swap(u,v);
for(int i=19;i>=0;--i) if(dep[fa[u][i]]>=dep[v]) u=fa[u][i];
if(u==v) return u;
for(int i=19;i>=0;--i) if(fa[u][i]!=fa[v][i]) u=fa[u][i],v=fa[v][i];
return fa[u][0];
}
int find(int u,int x) {for(int i=19;i>=0;--i) if(x>>i&1) u=fa[u][i];return u;}
void ins(int u,int v)
{
if(vs[u]!=vs[0]) vs[u]=vs[0],o.pb(u);
if(vs[v]!=vs[0]) vs[v]=vs[0],o.pb(v);e1[u].pb(v);++dg[v];
}
void slv()
{
bool res=1;++vs[0];
for(int i=1;i<m;++i)
if(dep[a[i]]>dep[a[i+1]] || a[i]==a[i+1]) {printf("No\n");return;}
for(int i=1,t;i<m;++i) if(dep[a[i]]==dep[a[i+1]])
{
t=lca(a[i],a[i+1]);
ins(find(a[i],dep[a[i]]-dep[t]-1),find(a[i+1],dep[a[i+1]]-dep[t]-1));
}for(auto i:o) if(!dg[i]) q.push(i);
while(!q.empty())
{
int u=q.front();q.pop();
for(auto v:e1[u]) {--dg[v];if(!dg[v]) q.push(v);}
}for(auto i:o) {if(dg[i]) res=0;dg[i]=0,e1[i].clear();}
o.clear();if(res) printf("Yes\n");else printf("No\n");
}
int main()
{
scanf("%d",&n);
for(int i=2,f;i<=n;++i) scanf("%d",&f),e[i].pb(f),e[f].pb(i);
dfs(1,0);scanf("%d",&c);
while(c--) {scanf("%d",&m);for(int i=1;i<=m;++i) scanf("%d",&a[i]);slv();}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 9ms
memory: 34956kb
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: 173ms
memory: 74012kb
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: 164ms
memory: 74564kb
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: 168ms
memory: 73408kb
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: 13ms
memory: 34040kb
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: 8ms
memory: 35036kb
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: 12ms
memory: 34232kb
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: 11ms
memory: 33864kb
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