QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#643522 | #8551. DFS Order 5 | MiniLong | WA | 11ms | 10112kb | C++14 | 4.3kb | 2024-10-15 21:35:18 | 2024-10-15 21:35:19 |
Judging History
answer
#include <bits/stdc++.h>
#define _rep(i, x, y) for(int i = x; i <= y; ++i)
#define _req(i, x, y) for(int i = x; i >= y; --i)
#define _rev(i, u) for(int i = head[u]; i; i = e[i].nxt)
#define pb push_back
#define fi first
#define se second
#define mst(f, i) memset(f, i, sizeof f)
using namespace std;
#ifdef ONLINE_JUDGE
#define debug(...) 0
#else
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#endif
typedef long long ll;
typedef pair<int, int> PII;
namespace fastio{
#ifdef ONLINE_JUDGE
char ibuf[1 << 20],*p1 = ibuf, *p2 = ibuf;
#define get() p1 == p2 && (p2 = (p1 = ibuf) + fread(ibuf, 1, 1 << 20, stdin), p1 == p2) ? EOF : *p1++
#else
#define get() getchar()
#endif
template<typename T> inline void read(T &t){
T x = 0, f = 1;
char c = getchar();
while(!isdigit(c)){
if(c == '-') f = -f;
c = getchar();
}
while(isdigit(c)) x = x * 10 + c - '0', c = getchar();
t = x * f;
}
template<typename T, typename ... Args> inline void read(T &t, Args&... args){
read(t);
read(args...);
}
template<typename T> void write(T t){
if(t < 0) putchar('-'), t = -t;
if(t >= 10) write(t / 10);
putchar(t % 10 + '0');
}
template<typename T, typename ... Args> void write(T t, Args... args){
write(t), putchar(' '), write(args...);
}
template<typename T> void writeln(T t){
write(t);
puts("");
}
template<typename T> void writes(T t){
write(t), putchar(' ');
}
#undef get
};
using namespace fastio;
#define multitest() int T; read(T); _rep(tCase, 1, T)
namespace Calculation{
const ll mod = 998244353;
ll ksm(ll p, ll h){ll base = p % mod, res = 1; while(h){if(h & 1ll) res = res * base % mod; base = base * base % mod, h >>= 1ll;} return res;}
void dec(ll &x, ll y){x = ((x - y) % mod + mod) % mod;}
void add(ll &x, ll y){x = (x + y) % mod;}
void mul(ll &x, ll y){x = x * y % mod;}
ll sub(ll x, ll y){return ((x - y) % mod + mod) % mod;}
ll pls(ll x, ll y){return ((x + y) % mod + mod) % mod;}
ll mult(ll x, ll y){return x * y % mod;}
}
using namespace Calculation;
const int N = 1e5 + 5;
int n, q, id, dfn[N], siz[N], pre[N], dep[N], f[N][25];
vector<int> G[N];
void dfs(int u, int fa){
siz[u] = 1, dfn[u] = ++id, pre[u] = f[u][0] = fa, dep[u] = dep[fa] + 1;
_rep(i, 1, 20) f[u][i] = f[f[u][i - 1]][i - 1];
for(auto &v : G[u]){
if(v == fa) continue;
dfs(v, u), siz[u] += siz[v];
}
}
int jump(int u, int k){
_req(i, 20, 0) if(k >> i & 1) u = f[u][i];
return u;
}
int m, a[N];
struct bit{
int c[N];
void add(int x, int val){for(; x <= n; x += x & -x) c[x] += val;}
int ask(int x){int res = 0; for(; x; x -= x & -x) res += c[x]; return res;}
int top, st[N];
void modify(int x){add(dfn[x], 1), st[++top] = x;}
int query(int x){return ask(dfn[x] + siz[x] - 1) - ask(dfn[x] - 1);}
void undo(){while(top) add(dfn[st[top--]], -1);}
}tr;
bool vis[N];
int main(){
read(n, q);
_rep(i, 2, n){
int u, v; read(u, v);
G[u].pb(v), G[v].pb(u);
}
_rep(i, 1, n) sort(G[i].begin(), G[i].end());
dfs(1, 0);
while(q--){
bool ok = 1;
read(m);
_rep(i, 1, m) read(a[i]), ok &= !vis[a[i]], vis[a[i]] = 1;
_rep(i, 1, m) vis[a[i]] = 0;
if(!ok){puts("No"); continue;}
int u = a[1], pos = 1, lst = a[1];
tr.modify(u);
while(pos <= m){
int t = siz[u];
_rep(i, 2, t){
if(pos == m) break;
pos++;
while(u && tr.query(u) == siz[u]) u = pre[u];
if(!u || a[pos] == pre[u] || !binary_search(G[u].begin(), G[u].end(), a[pos])){ok = 0; break;}
u = a[pos], tr.modify(u);
}
if(!ok) break;
pos++;
if(pos <= m){
if(jump(lst, dep[lst] - dep[a[pos]]) == a[pos]){ok = 0; break;}
int t = pre[a[pos]];
if(!t || jump(lst, dep[lst] - dep[t]) != t){ok = 0; break;}
lst = t, u = a[pos], tr.modify(u);
}
}
puts(ok ? "Yes" : "No");
tr.undo();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 9780kb
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: 11ms
memory: 10112kb
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'