QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#588862#8551. DFS Order 5BreakPlusWA 35ms15356kbC++142.5kb2024-09-25 14:58:022024-09-25 14:58:02

Judging History

你现在查看的是最新测评结果

  • [2024-09-25 14:58:02]
  • 评测
  • 测评结果:WA
  • 用时:35ms
  • 内存:15356kb
  • [2024-09-25 14:58:02]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> Pr;
#define fi first
#define se second
#define mkp make_pair
#define pb emplace_back
#define popcnt __builtin_popcountll
const ll mod = 998244353;
inline ll read(){
	ll x=0, f=1; char ch=getchar();
	while(ch<'0' || ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
	while(ch>='0' && ch<='9') x=x*10+ch-'0', ch=getchar();
	return x*f;
}
inline ll lg2(ll x){ return 63^__builtin_clzll(x); }
inline ll qpow(ll a,ll b){
	ll ans=1, base=a;
	while(b){
		if(b&1) ans=ans*base%mod;
		base=base*base%mod; b>>=1;
	}
	return ans;
}
ll n,q,k,sz[100005],f[100005],dfn[100005],out[100005],tim;
vector<ll>E[100005];
void dfs(ll x,ll fa){
	f[x]=fa; sz[x]=1;
	dfn[x]=(++tim);
	for(auto y: E[x]){
		if(y==fa) continue;
		dfs(y, x);
		sz[x]+=sz[y];
	}
	out[x]=tim;
}

bool chk=1;
ll c[100005];
vector<ll>stk;
void upd(ll x,ll w){
	stk.pb(x);
	for(; x<=n; x+=x&(-x)){
		c[x] += w;
	}
}
ll query(ll x){
	ll res = 0;
	for(; x; x-=x&(-x)) res += c[x];
	return res;
}
ll seq[100005], pt;
void check(ll x){
	if(seq[pt]!=x) chk=0;
	if(query(out[x])>query(dfn[x]-1)) {chk=0; return;}
	upd(dfn[x], 1); stk.pb(dfn[x]);
	pt++;
}
void visit(ll x,ll step){
	// cout<<"visiting "<<x<<" with "<<step<<endl;
	check(x);step--;
	if(!chk) return;
	while(step){
		if(f[seq[pt]] != x){
			chk=0;
			return;
		}
		ll val=min(sz[seq[pt]],step);
		visit(seq[pt], val);
		step-=val;
	}
}
void init(){ }
bool pro(ll x,ll y){
	if(dfn[y]<=dfn[x] && dfn[x]<=out[y]) return 0;
	y=f[y];
	return dfn[y]<=dfn[x] && dfn[x]<=out[y];
}
void procedure(){
	n=read(),q=read();
	for(ll i=1;i<n;i++) {
		ll u=read(), v=read();
		E[u].pb(v); E[v].pb(u);
	}	
	dfs(1,0);
	vector<string>ans;
	for(ll i=1;i<=q;i++){
		stk.clear();
		ll k=read(); 
		for(ll j=1;j<=k;j++){
			seq[j]=read();
		} 
		chk=1; pt=1; ll res=k;
		while(pt<=k && chk){
			if(pt>1){
				chk &= pro(seq[pt-1], seq[pt]);
			}
			if(!chk) break;
			ll val=min(res,sz[seq[pt]]);
			visit(seq[pt], val);
			res -= val;
		}
		if(chk) ans.pb("Yes");
		else ans.pb("No");
		if(i==89){
			for(ll j=1;j<=k;j++) cout<<seq[j]<<" "; cout<<endl;
		}

		for(auto x: stk) upd(x, -1);
	}
	for(auto st: ans) cout<<st<<endl;
}
int main(){
	#ifdef LOCAL
		assert(freopen("input.txt","r",stdin));
		assert(freopen("output.txt","w",stdout));
	#endif
	ll T=1;
	init();
	while(T--) procedure();
	return 0;
}


詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 7888kb

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: 35ms
memory: 15356kb

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:

4 2 8 
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...

result:

wrong answer 1st words differ - expected: 'No', found: '4'