QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#640346 | #8551. DFS Order 5 | lvkaiyi0811 | WA | 164ms | 13820kb | C++20 | 1.0kb | 2024-10-14 11:08:10 | 2024-10-14 11:08:10 |
Judging History
answer
#include<bits/stdc++.h>
#define eb emplace_back
using namespace std;
typedef long long ll;
const ll _=1e5+5;
ll n,m,q,x,y,t,b[_],c[_],dfn[_],sz[_],dep[_],d[18][_],e[_],i,j;bool f[_];vector<ll>E[_];
inline void p1(ll x,ll fa){
d[0][t]=e[x]=fa;dfn[x]=++t;sz[x]=1;
for(ll y:E[x])if(y!=fa)dep[y]=dep[x]+1,p1(y,x),sz[x]+=sz[y];
}
inline ll p2(ll x,ll y){return dep[x]<dep[y]?x:y;}
inline ll p3(ll x,ll y){
if(x==y)return x;x=dfn[x];y=dfn[y];if(x>y)swap(x,y);
ll t=__lg(y-x);return p2(d[t][x],d[t][y-(1<<t)]);
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n>>q;
for(i=1;i<n;i++)cin>>x>>y,E[x].eb(y),E[y].eb(x);
p1(1,0);
for(i=1;i<18;i++)for(j=1;j<=n-(1<<i);j++)
d[i][j]=p2(d[i-1][j],d[i-1][j+(1<<(i-1))]);
while(q--){
cin>>m>>x;memset(f,0,sizeof(f));
t=1;b[1]=x;c[1]=0;f[x]=1;
for(i=1;i<m;i++){
cin>>y;
if(f[y]||p3(x,y)!=e[y])break;
for(;t&&dep[b[t]]>=dep[y];t--)if(i<c[t]+sz[b[t]])break;
if(t&&dep[b[t]]>=dep[y])break;
b[++t]=x=y;c[t]=i;f[x]=1;
}
cout<<(i<m?"No\n":"Yes\n");
while(++i<m)cin>>y;
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 13820kb
input:
6 7 1 2 1 3 2 4 3 5 2 6 2 4 1 2 4 2 2 4 3 2 4 4 2 4 5 2 4 6 6 1 2 6 4 3 5
output:
No No Yes No No Yes Yes
result:
ok 7 tokens
Test #2:
score: -100
Wrong Answer
time: 164ms
memory: 11736kb
input:
10 100000 7 2 1 7 7 10 8 6 8 7 1 3 4 5 9 5 5 8 8 8 9 7 2 8 1 6 1 4 8 3 5 2 6 7 10 3 9 9 1 1 1 8 10 3 2 9 3 8 7 3 7 5 6 2 8 5 9 1 6 3 4 6 2 1 3 5 8 9 2 4 9 1 3 2 1 5 5 8 5 1 7 9 10 5 2 9 2 6 4 10 6 3 8 3 4 5 8 2 8 4 9 4 10 1 2 4 3 3 6 3 1 3 6 1 1 6 8 3 1 3 7 3 2 3 9 1 5 4 3 7 8 10 9 4 2 3 10 2 5 4 3 ...
output:
No No No Yes No No No No Yes No No No No No No Yes No No No No No No No No No No No No No No No Yes No No No No No No Yes No No No No No Yes Yes 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 Yes Yes No No No No Yes No No No No No No No No Yes No No No No No No No ...
result:
wrong answer 89th words differ - expected: 'No', found: 'Yes'