QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#491367 | #8551. DFS Order 5 | ucup-team2307# | WA | 32ms | 3832kb | C++23 | 1.8kb | 2024-07-25 19:04:44 | 2024-07-25 19:04:47 |
Judging History
answer
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
typedef long long ll;
#define int ll
using namespace std;
const int N = 1e5+100;
const int K = 20;
vector<int> g[N];
int pr[N][K];
int dep[N];
void dfs(int v, int p, int d = 0)
{
dep[v] = d;
pr[v][0] = p;
for (int i : g[v])
if (i != p)
dfs(i, v, d+1);
}
bool ask(vector<int> qur)
{
set<pair<int, int> > alr;
int s = qur[0];
for (int i=1; i<int(qur.size()); i++)
{
int v = qur[i];
if (v == 1)
return false;
if (g[s].size() > 1)
{
if (pr[v][0] != s)
return false;
if (alr.count({s, v}))
return false;
alr.insert({s, v});
s = v;
}
else
{
for (int i=K-1; i>=0; i--)
if (dep[pr[s][i]] >= dep[v])
s = pr[s][i];
int sup = pr[s][0];
if (pr[v][0] != sup)
return false;
alr.insert({sup, s});
if (alr.count({sup, v}))
return false;
alr.insert({sup, v});
s = v;
}
}
return true;
}
void solve()
{
int m;
cin>>m;
vector<int> v(m);
for (int& i : v)
cin>>i;
if (ask(v))
cout<<"Yes\n";
else
cout<<"No\n";
}
main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, q;
cin>>n>>q;
for (int i=1; i<n; i++)
{
int x, y;
cin>>x>>y;
g[x].pb(y);
g[y].pb(x);
}
dfs(1, 1);
for (int i=0; i+1<K; i++)
for (int v=1; v<=n; v++)
pr[v][i+1] = pr[v][pr[v][i]];
while (q--)
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3832kb
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: 32ms
memory: 3576kb
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 No No No No No No No No N...
result:
wrong answer 899th words differ - expected: 'No', found: 'Yes'