QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#537125 | #8551. DFS Order 5 | obiwan114 | WA | 26ms | 5652kb | C++20 | 1.9kb | 2024-08-29 21:18:38 | 2024-08-29 21:18:38 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
//#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
const int MAXX = 1e5 + 5;
vector<int>g[MAXX];
int fa[MAXX],dep[MAXX],siz[MAXX],son[MAXX],top[MAXX],dfn[MAXX],rnk[MAXX];
void dfs1(int u){
son[u] = -1;
siz[u] = 1;
for(int v : g[u]){
if(dep[v])continue;
dep[v] = dep[u] + 1;
fa[v] = u;
dfs1(v);
siz[u] += siz[v];
if(son[u] == -1 || siz[v] > siz[son[u]]){
son[u] = v;
}
}
}
//int cnt = 0;
//void dfs2(int u,int t){
// cnt++;
// dfn[u] = cnt;
// rnk[cnt] = u;
// top[u] = t;
// if(son[u] == -1)return;
// dfs2(son[u],t);
// for(int v : g[u]){
// if(v == fa[u])continue;
// if(v == son[u])continue;
// dfs2(v,v);
// }
//}
int n,q;
int a[MAXX];
void solve() {
int k;
cin >> k;
for(int i = 1;i <= k;i++){
cin >> a[i];
}
vector<int>dp(n + 2);
dp[a[1]]++;
for(int i = 2;i <= k;i++){
int x = a[i - 1];
int y = a[i];
if(x != fa[y] && son[x] != -1){
cout << "No\n";
return;
}
while(x != fa[y] && x != 1){
// if(dp[x] < siz[x]){
// cout << "No\n";
// return;
// }
dp[fa[x]] += dp[x];
x = fa[x];
}
if(x != fa[y]){
cout << "No\n";
return;
}
if(dp[a[i]]){
cout << "No\n";
return;
}
}
cout << "Yes\n";
}
signed main() {
ios::sync_with_stdio(false), cin.tie(0);
cin >> n >> q;
for(int i = 1;i < n;i++){
int u,v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
dep[1] = 1;
dfs1(1);
// dfs2(1,1);
while (q--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5652kb
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: 26ms
memory: 5616kb
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 114th words differ - expected: 'No', found: 'Yes'